【发布时间】:2012-07-18 03:32:00
【问题描述】:
我正在尝试将 JSON 数据从 iPhone 应用程序发送到我的 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 数据存在问题。有什么想法吗?
编辑:在下面回答
【问题讨论】:
标签: ios asp.net-mvc json post