2

我正在尝试从我的 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];
}

谁能帮我?

4

1 回答 1

0

您对 requestString 和 aRequest 执行此操作,但不是在格式化和添加之后..

尝试

httpBody = [httpBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *aData = [httpBody dataUsingEncoding:NSUTF8StringEncoding];
于 2009-11-27T08:40:24.580 回答