以下代码出现问题
-(void)AddEmpService:(NSDictionary *)params
{
recordResults = FALSE;
OutPutStringName = [[NSMutableString alloc] init];
[OutPutStringName appendString: @"string"];
NSString *urlstr =[NSString stringWithFormat:@"http://www.seen.com/SeenApi/Service.svc/EmpService?type=Insert&Id=&ClassId=%@&Name=%@&Desg=%@&Age=%@&Add=%@&Sal=%@&Gend=%@&Phone=%@&EmpId=%@",[params objectForKey:@"Id"],[params objectForKey:@"EmpName"],[params objectForKey:@"EmpDesignation"],[params objectForKey:@"EmpAge"],[params objectForKey:@"EmpAddress"],[params objectForKey:@"EmpSalary"],[params objectForKey:@"EmpGender"],[params objectForKey:@"EmpPhone"],[params objectForKey:@"EmpId"]];
NSLog(@"dict is %@",params);
urlstr=[urlstr stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSLog(@"%@",urlstr);
NSURL *url= [NSURL URLWithString:urlstr];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSLog(@"the request %@",theRequest);
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [NSMutableData data];
}
else
{
NSLog(@"theConnection is NULL");
}
}
NSLog(@"%@",urlstr);是
http://www.seen.com/SeenApi/Service.svc/EmpService?type=Insert&Id=&ClassId=63&Name=Mark&Desg=Teacher&Age=25&Add=New%%20York&Sal=5000&Gend=Male&Phone=0987654321&EmpId=235
但是获取空值 NSLog(@"请求 %@",theRequest);
the request <NSMutableURLRequest: 0x1c0c7ae0> { URL: (null) }
2017-11-21 14:07:36.262 Emp[7070:2394869] ERROR with theConenction
请帮我找出问题所在。TIA
最佳答案
尝试使用这个:
NSMutableURLRequest * theRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[urlstr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]]];
关于ios - <NSMutableURLRequest : 0x1c0c7ae0> { URL: (null) } in Objective C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47408964/