【发布时间】:2014-10-14 10:59:07
【问题描述】:
我试图将字符串值发布到 Sql Server.like this
NSString *post =[NSString stringWithFormat:@"?&name=%@&password=%@&pin=%@&email=%@&phone=%@&address=%@&city=%@&status=%@",
name, password ,pin ,email ,phone,address,city,status];
NSLog(@"post%@",post);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://202.65.154.108:8080/SaveDollar/rest/deals/add"]]];
NSLog(@"getData%@",request);
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
[request setHTTPBody:postData];
NSLog(@"getData%@",request);
con3 = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(con3)
{ webData3=[NSMutableData data];
NSLog(@"Connection successful");
NSLog(@"GOOD Day My data %@",webData3);
}
else
{
NSLog(@"connection could not be made");
}
我试过这样连接成功。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSString *responseText = [[NSString alloc] initWithData:webData3 encoding: NSASCIIStringEncoding];
NSLog(@"Response: %@", responseText);}
但是得到这样的响应 HTTP Status 500 - Request processing failed;嵌套异常是 java.lang.NullPointerException
我不明白我的错误是什么所以请给我任何想法,并请告诉我我的代码有什么问题。
感谢高级。
【问题讨论】:
标签: ios objective-c json post