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");
       }

所以当 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 回答