当我向我的网络服务发出要求时,如“Ö”,我回复500“请求处理有误” 这就是我对SOS的看法。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error = nil;
dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:self.responseData error:&error];
for (id key in dict) {
NSLog(@"%@=%@", key, [dict objectForKey:key]);
}
If I send a message with just plain english it works fine.
I m not sure if the error is on the server-side or in the app itself. This is how I send my JSON POST:
- (void)stringWithUrl:(NSURL *)url jsonReq:(NSString *)json{
self.requestURL = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease];
self.responseData = [NSData dataWithBytes:[json UTF8String] length:[json length]];
[self.requestURL setHTTPMethod:@"POST"];
[self.requestURL setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[self.requestURL setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[self.requestURL setValue:@"application/json" forHTTPHeaderField:@"UTF-8"];
[self.requestURL setValue:[NSString stringWithFormat:@"%d", [self.responseData length]] forHTTPHeaderField:@"Content-Length"];
[self.requestURL setHTTPBody: self.responseData];
这也是网络服务如何看待:
....
[WebService(Namespace = "http://mypage.com/webservicesF")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
[System.Web.Script.Services.ScriptService]
.....
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]