メソッドを POST 以外に設定して変更可能なリクエストに本文を設定すると、本文がリクエストに含まれず、サーバーが応答したときに kCFErrorDomainCFNetwork エラー 303 (kCFErrorHTTPParseFailure) が発生します。メソッドを POST に変更するだけで、リクエストがエラーなしで処理されます。body を他のメソッドにアタッチする方法はありますか? それとも、すべて 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];