1

サーバーにデータを投稿するときに文字に問題があります

NSString *url = [NSString stringWithFormat:@"http://100.200.30.400/iph/req.php?ph=%@&lat=%@&lon=%@&name=%@&stor=%@",self.phone,self.latitude,self.longtitude,self.name,self.stor];

       NSLog(@"url: %@",url);
       NSString *url2 ;
       url2 = [NSString stringWithUTF8String:[url UTF8String]];
        NSLog(@"url2: %@",url2);
       NSURL *reqUrl = [[NSURL alloc] initWithString:url2 ];
       NSURLRequest *request = [[NSURLRequest alloc] initWithURL:reqUrl];
       NSError *error;
       NSURLResponse *response;
       NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
       NSStringEncoding responseEncoding = NSUTF8StringEncoding;
       if ([response textEncodingName]) {
           CFStringEncoding cfStringEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)[response textEncodingName]);
           if (cfStringEncoding != kCFStringEncodingInvalidId) {
               responseEncoding = CFStringConvertEncodingToNSStringEncoding(cfStringEncoding); 
           }
       }
       [reqUrl release];
       NSString *dataString = [[NSString alloc] initWithData:data encoding:responseEncoding];
       //NSLog(@"dataString: %@",dataString);
       if ([dataString intValue] > 0 )
       {
          NSLog(@"EVERETHING IS GOOD");
       }

SO self.name が英語の場合は正常に機能しますが、ロシア語の記号を試している場合は機能しません。ブラウザでロシア語の記号で試してみましたが、問題がロシア語の記号にある理由はうまくいきます。アプリをロシア語の記号で動作させるにはどうすればよいですか? ありがとう

4

1 に答える 1

0

だから私の問題のために、URLの文字列を返す友人の関数を使用しました

ここにあります

-(NSString *)encodeString:(NSString *)string {
string = [string lowercaseString];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol1 withString:kEncodedSymbol1];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol2 withString:kEncodedSymbol2];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol3 withString:kEncodedSymbol3];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol4 withString:kEncodedSymbol4];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol5 withString:kEncodedSymbol5];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol6 withString:kEncodedSymbol6];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol7 withString:kEncodedSymbol7];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol8 withString:kEncodedSymbol8];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol9 withString:kEncodedSymbol9];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol10 withString:kEncodedSymbol10];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol11 withString:kEncodedSymbol11];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol12 withString:kEncodedSymbol12];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol13 withString:kEncodedSymbol13];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol14 withString:kEncodedSymbol14];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol15 withString:kEncodedSymbol15];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol16 withString:kEncodedSymbol16];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol17 withString:kEncodedSymbol17];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol18 withString:kEncodedSymbol18];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol19 withString:kEncodedSymbol19];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol20 withString:kEncodedSymbol20];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol21 withString:kEncodedSymbol21];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol22 withString:kEncodedSymbol22];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol23 withString:kEncodedSymbol23];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol24 withString:kEncodedSymbol24];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol25 withString:kEncodedSymbol25];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol26 withString:kEncodedSymbol26];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol27 withString:kEncodedSymbol27];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol28 withString:kEncodedSymbol28];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol29 withString:kEncodedSymbol29];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol30 withString:kEncodedSymbol30];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol31 withString:kEncodedSymbol31];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol32 withString:kEncodedSymbol32];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol33 withString:kEncodedSymbol33];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol34 withString:kEncodedSymbol34];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol35 withString:kEncodedSymbol35];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol36 withString:kEncodedSymbol36];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol37 withString:kEncodedSymbol37];
string = [string stringByReplacingOccurrencesOfString:kCyrrilicSymbol38 withString:kEncodedSymbol38];
return string;

}

于 2012-04-16T15:16:05.973 に答える