【问题标题】:sending XML file from IPhone to a server using Post Method使用 Post 方法将 XML 文件从 iPhone 发送到服务器
【发布时间】:2009-11-27 08:28:23
【问题描述】:

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

谁能帮帮我?

【问题讨论】:

    标签: iphone post nsurlrequest


    【解决方案1】:

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

    试试

    httpBody = [httpBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    

    之前

    NSData *aData = [httpBody dataUsingEncoding:NSUTF8StringEncoding];
    

    【讨论】:

    • 我试过但没有成功。但是当我通过浏览器将相同的请求传递给服务器时,它可以工作。
    • 它崩溃了...我认为是因为它将 %3D 视为格式说明符,但我使用了反斜杠..但这也没有用。任何想法............如何做到......感谢您的回复
    猜你喜欢
    • 2015-11-18
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 2023-03-03
    • 2015-02-26
    • 2016-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多