2012-04-10 13 views
1

にデータをポストするときにサーバーにデータをポストするとき、私はself.nameが英語のときに問題サーバー

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、それが正常に動作手紙に問題があるが、私はロシアのシンボルをしようとしているとき、そうではありませんワーキング。私はブラウザでロシアのシンボルでそれを試してみました。それは問題がロシアのシンボルである理由は良いです。私はロシアのシンボルでアプリを動作させるために何をしなければならないのですか? THANKS

+0

ですNSUTF16StringEncoding'、そうですか? – dasblinkenlight

+0

私はNSUTF8StringEncodingを試しています –

答えて

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; 

}