[英]How to make a PUT HTTP request in ios sdk?
In my application I need to make a PUT type request. 在我的应用程序中,我需要发出一个PUT类型请求。 I have followed the below steps
我已经按照以下步骤
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];
For POST and GET I am getting correct output. 对于POST和GET,我得到正确的输出。
I have searched a lot but i am not getting any solution.Please suggest me any possible solution . 我已经搜索了很多,但没有任何解决方案。请向我提出任何可能的解决方案。
Thanks in advance 提前致谢
Try this 尝试这个
For xml request body 对于xml请求正文
Set [request setValue:@"application/x-www-form-urlencoded;charset=utf-8;application/form-data" forHTTPHeaderField:@"Content-Type"];
OR
For json request body 对于JSON请求正文
Set [request setValue:@"application/x-www-form-urlencoded;charset=utf-8;application/json" forHTTPHeaderField:@"Content-Type"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.