Can iOS devices send PUT requests to Rails apps?

断了今生、忘了曾经 提交于 2019-11-30 19:41:56

You can make an NSMutableURLRequest and set the HTTP method:

- (void)setHTTPMethod:(NSString *)method

Give it the string @"PUT".

Here is how you can create an NSURLConnection from such a request.

NSMutableURLRequest *myMutableRequest[[NSMutableURLRequest alloc] initWithURL:myURL];
[myMutableRequest setHTTPMethod:@"PUT"];
[NSURLConnection connectionWithRequest:myMutableRequest delegate:myDelegate];

Actually @akshay1188 has a workable solution, but I think the more elegant approach is to add the "application/x-www-form-urlencoded" content type to the request:

[request setHTTPMethod:@"PUT"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

Set the HTTP method type as @"POST"

And add a parameter to the request body as: @"PUT" for key @"_method"

It should work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!