当我们在 iOS SDK 中将 URL 发布到服务器时,收到 Invalid Request 的原因是什么。我发送的 URL 是正确的,我发布的数据也是正确的。我也在 RestClient 中尝试过,即使我也收到同样的错误 Invalid Request 。任何人都可以帮助我这是什么原因。提前致谢。
- (NSURLConnection *) executeAsyncHttpPost :(NSString *) baseURL :(NSString *) method
:(id) jsonParams :(int)callerTag
{
NSLog(@"jsonParams: %@", jsonParams);
NSString *urlstr = [NSString stringWithFormat:@"%@", baseURL];
urlstr = [urlstr stringByAppendingFormat:method];
NSLog(@"urlstr: %@", urlstr);
NSString *postLength = [NSString stringWithFormat:@"%d", [jsonParams length]];
NSURL *pUrl = [NSURL URLWithString:urlstr];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:pUrl];
NSData *requestData = [[NSData alloc] initWithData:[jsonParams dataUsingEncoding:NSASCIIStringEncoding]];
NSString* myString;
myString = [[NSString alloc] initWithData:requestData encoding:NSASCIIStringEncoding];
NSLog(@"myString: %@", myString);
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
self.tag = callerTag;
return [super initWithRequest:request delegate:delegateResponder];
}