每当我在可变请求上设置主体并且方法设置为 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];