-1

サーバー上でリクエストを作成していますが、URL にスペースが含まれています

http://xxxxxxxx.com/api/api.php?func=showAllwedsdwewsdsd¶ms[]=サウジアラビア%20アラブ¶ms[]=all

Bad URL というエラーが表示されたので、

使った

   downloadURL = [downloadURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

しかし、これにより、奇妙なURLを取得しています

 http://sdsdsdsdsdsd.com/api/api.php?func=showAllsdsd&params5262721536=Saudi              0X0P+0rabia&params5 8288=All

私も使っています

  downloadURL= [downloadURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

しかし、再び奇妙なURLのような

     http://xxxxxxxxx.com/api/api.php?func=showsdsdsd&params[]=Saudi 0X1.240DC0D824P-807rabia&params[]=All

この問題を解決するにはどうすればよいですか

コードの大部分の貼り付けを編集

   PropertyXMLDownloader *download=[[PropertyXMLDownloader alloc]init];
  [download setDelegate:self];
   firstAppDelegate *del=(firstAppDelegate *)[[UIApplication sharedApplication]delegate];
   NSLog(@"Country is %@",del.country);
   NSLog(@"State is %@",del.state);
//  del.country=[del.country stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

   NSString *downloadURL=[NSString stringWithFormat:@"http://xxxxxxxx.com/api/api.php?func=showAll&params[]=Saudi Arabia&params[]=%@",@"all"];
      // downloadURL= [downloadURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
       //downloadURL = [downloadURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

   NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@" "];
   downloadURL = [[downloadURL componentsSeparatedByCharactersInSet: doNotWant]    componentsJoinedByString:@"%20"];


    NSLog(downloadURL); 
    [download startDownloading:downloadURL];
4

3 に答える 3

1

%20 は、%@ や %g などのデータ引数として認識されている可能性があります。を使用して NSString を定義してみてください

NSString *urlString = [NSString stringWithFormat:@"http://xxxxxxxx.com/api/api.php?func=showAllwedsdwewsdsd&params[]=Saudi%20Arab&params[]=all"];

警告が表示されます。パーセント記号の前に別の記号を追加して、パーセント記号を「エスケープ」します。

NSString *urlString = [NSString stringWithFormat:@"http://xxxxxxxx.com/api/api.php?func=showAllwedsdwewsdsd&params[]=Saudi**%**%20Arab&params[]=all"];

そして警告は消えます。

于 2012-08-04T07:41:53.393 に答える
1

これを試して。

NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@" "];
downloadURL = [[downloadURL componentsSeparatedByCharactersInSet: doNotWant]   componentsJoinedByString:@"%20"];
于 2012-08-04T06:55:43.043 に答える
0

あなたの問題はこれです:

NSLog(downloadURL); 

次のように置き換えてみてください。

NSLog(@"%@", downloadURL); 

そしてすべてがうまくいくでしょう。

すべての回避策を使用stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncodingして忘れることができます。

(説明: downloadURL% 記号が含まれているため、最初の引数としてフォーマット文字列を期待する NSLog ではうまく機能しません。% 記号は置き換えられるプレースホルダーを識別します)。

于 2012-08-04T06:47:13.003 に答える