简体   繁体   English

使用Post方法从iPhone将XML文件发送到服务器

[英]sending XML file from IPhone to a server using Post Method

I am trying to send the data to server from my Iphone client. 我正在尝试将数据从Iphone客户端发送到服务器。 It works fine for most values but when itry to send a string like "IPhone+Cocoa" the server shows the string as "IPhone Cocoa". 对于大多数值来说,它都可以正常工作,但是当尝试发送类似“ IPhone + Cocoa”的字符串时,服务器会将字符串显示为“ IPhone Cocoa”。 I have tried to google it but without success is there any why of doing it. 我试图用谷歌搜索它,但没有成功,为什么要这样做。

Here is my code 这是我的代码

-(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];
}

Can anyone help me? 谁能帮我?

You do this for requestString and aRequest,but not after formatting together with your addition.. 您对requestString和aRequest进行此操作,但在与添加内容一起格式化之后不进行此操作。

Try 尝试

httpBody = [httpBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

before 之前

NSData *aData = [httpBody dataUsingEncoding:NSUTF8StringEncoding];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM