这是提交代码:
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:assembleuRL]];// cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:45.0];#if (SERVER_TARGET_ARGS_ALLOWED==1)[req setValue:@"application/Json" forhttpheaderFIEld:@"Content-Type"];[req setValue:@"application/Json" forhttpheaderFIEld:@"Accept"];[req sethttpMethod:ServerMessageMethods[operation]]; //value is @"POST" or other method name#endif //run the payload into a JsONSBJsonWriter *Json = [[SBJsonWriter alloc] init];Nsstring *encodedPayload = [Json stringWithObject:payload];encodedPayload = [Nsstring stringWithFormat:@"%@",[encodedPayload stringByAddingPercentEscapesUsingEnCoding:NSUTF8StringEnCoding]];NSData *dataPayload = [encodedPayload dataUsingEnCoding:NSUTF8StringEnCoding];[req sethttpBody:dataPayload];NSURLConnection *conn = [NSURLConnection connectionWithRequest:req delegate:self];解决方法 我尝试找到更多关于它的最新信息,但是有一个关于你正在谈论的确切问题的旧帖子: http://lists.apple.com/archives/cocoa-dev/2004/May/msg01847.html
基本上,他们提到这是代码中的一个错误.可悲的是,我希望能找到一些更新的东西,证实这一点.
我一直在使用的代码是ASIHTTPRequest,它绝对可以做PUT请求,因为它们使用较低级别的代码来创建http消息,并且不依赖于NSMutableUrlRequest.
此外,我发现另一个博客文章谈论了这个问题,以及您需要为PUT请求提供什么. http://iphonedevelopment.blogspot.com/2008/06/http-put-and-nsmutableurlrequest.html
博客文章:
When using NSMutableURLRequest to do an http PUT request,add the following line of code (req is the NSMutableURLRequest):
[req setValue:@"application/x-www-form-urlencoded" forhttpheaderFIEld:@"Content-Type"];
总结That’s all there is to it. If you add this line of code,your PUT requests will work just fine.
以上是内存溢出为你收集整理的iphone – NSURLRequest在方法不POST时无法处理HTTP主体?全部内容,希望文章能够帮你解决iphone – NSURLRequest在方法不POST时无法处理HTTP主体?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)