我正在尝试从我的Iphone客户端向服务器发送数据。它适用于大多数值,但是当它发送像“IPhone + Cocoa”这样的字符串时,服务器会将字符串显示为“IPhone Cocoa”。我试图谷歌它,但没有成功是为什么这样做。
这是我的代码
-(void)sendRequest:(NSString *)aRequest
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:kURLRequest]];
NSString *httpBody = [NSString stringWithFormat:@"%@=%@",[requestString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[aRequest stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData *aData = [httpBody dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:aData];
[request setHTTPMethod:@"POST"];
self.feedURLConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
任何人都可以帮助我吗?
答案 0 :(得分:0)
您可以对requestString和aRequest执行此操作,但在与您的添加一起格式化之后不会这样做。
尝试
httpBody = [httpBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
前
NSData *aData = [httpBody dataUsingEncoding:NSUTF8StringEncoding];