【发布时间】:2011-07-22 10:18:32
【问题描述】:
我正在通过网络服务发送一个帖子请求,但我没有得到我想要的响应。
这是我的代码:
NSString *newurlString = [NSString stringWithFormat:@"{\"name\":\"asit\",\"email\":\"m.kulkarni@easternenterprise.com\",\"businessType\":\"1\",\"score\":30}"];
NSString * url = @"http://www.nieuwe-dag.nl/mobile_be/public/?action=saveScore";
//NSString *urlString =[NSString stringWithFormat:@"name=%@&email=%@&businessType=%d&score=%d",name, email, bussinesstype, score];
NSData *postData = [newurlString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"urlString::%@",newurlString);
NSLog(@"postLength::%@",postLength);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:300];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *theConnection =[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection){
webData = [[NSMutableData data] retain];
}
else {
NSLog(@"theConnection is NULL");
}
【问题讨论】:
标签: iphone objective-c ios json