【发布时间】:2010-08-12 14:58:17
【问题描述】:
每当我在可变请求上设置主体并且方法设置为 POST 以外的任何内容时,主体都不会包含在请求中,并且当服务器回复时我会收到 kCFErrorDomainCFNetwork 错误 303 (kCFErrorHTTPParseFailure)。将方法更改为 POST 即可使请求顺利通过。有没有办法将主体附加到其他方法,或者我们是否对所有内容都坚持使用 POST?
这是提交代码:
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 JSON
SBJsonWriter *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];
【问题讨论】:
-
是的,我遇到了关于 PDF 的 Content-Length 问题,但我想我会分享。 ssbits.wordpress.com/tag/kcferrordomaincfnetwork
标签: iphone cocoa nsurlrequest