如何在ios sdk中发出PUT HTTP请求?

时间:2014-06-25 12:18:52

标签: ios http nsurlconnection nsurlrequest put

在我的应用程序中,我需要发出 PUT 类型请求。我已按照以下步骤进行操作

NSString *path = @"http://hostname/api/Account/VerifyUser?applicationToken=72B648C6-B2B7-45ED-BA23-2E8AAA187D2C&emailID=xxx@gmail.com&password=aaaaa";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
                                [NSURL URLWithString:path]];
[request setHTTPMethod:@"PUT"];
[request setValue:[NSString stringWithFormat:@"%d", string.length] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded;charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[string dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];

对于POST和GET,我得到了正确的输出。

我已经搜索了很多,但我没有得到任何解决方案。请建议我任何可能的解决方案。

提前致谢

1 个答案:

答案 0 :(得分:0)

试试这个

对于xml请求正文

    Set [request setValue:@"application/x-www-form-urlencoded;charset=utf-8;application/form-data" forHTTPHeaderField:@"Content-Type"];

OR

对于json请求正文

    Set [request setValue:@"application/x-www-form-urlencoded;charset=utf-8;application/json" forHTTPHeaderField:@"Content-Type"];