我正在尝试从 iPhone 应用程序将 JSON 数据发布到我的 asp.net MVC 服务器。我的服务器中的方法如下所示:
[HttpPost]
public String MyMethod(Stream anUpload) { ... }
这是从我的应用程序发布 JSON 的代码:
NSString *theURL = [NSString stringWithFormat:@"http://192.168.1.103/MyServer/MyMethod"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:theURL]];
[theRequest setHTTPMethod:@"POST"];
// Serialize my data.
NSData *theData = [NSJSONSerialization dataWithJSONObject:theList options:kNilOptions error:nil];
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:[NSString stringWithFormat:@"%d", [theData length]] forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:theData];
但是,当我发送请求时,我只是从服务器收到一条错误消息, MyMethod() 永远不会被调用。我假设 ASP 接受 POST 数据存在问题。有任何想法吗?
编辑:下面回答