IIS7 .NET Framework 4.0 で実行されている C# で記述された WCF Web サービスへの POST 要求を作成しようとしています。
Web サービスは GET 要求に対して機能しますが、POST メソッドが機能していないようです。.NET に切り替える前に、サーバー側に PHP を使用していたという背景があります。
iOS での私のリクエストのコード:
NSArray *jsonKeys = [NSArray arrayWithObjects:@"zip", nil];
NSArray *jsonValues = [NSArray arrayWithObjects: zipcode, nil];
NSDictionary *jsonDict = [NSDictionary dictionaryWithObjects:jsonValues forKeys:jsonKeys];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"%@", jsonString);
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/weather", ConnectionString3]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [jsonData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:jsonData];
WCF Web サービスの C# コード:
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/weather")]
List<Weather> GetWeatherMethod(string zip);
エラーが発生したサーバーからの XML 応答を示す iOS 側の応答をログに記録し、サーバー側のログを確認しましたが、問題はないようです。どんな助けでも大歓迎です。
私が見つけることができるサーバーからのログのみが読み取ります:
(Date and Time) (Server IP) POST /PeopleService/PeopleService.svc/weather - 80 - (local app ip) AppName/1.0+CFNetwork/609+Darwin/11.4.2 400 0 0 0