可能重复:从文本字段获取值到webservice
我之前发过类似的问题,但我没有得到适当的帮助!我在重复 . 我正在将参数从我的textField上传到web服务 . 一切顺利,但我无法检索webservice中的值 . PLZ PLZ帮忙!!这是我的代码:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(textView1.text);
NSString *soapMsg = [[NSString alloc] initWithFormat:@"?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
""
"\n"
"%@\n"
"%@\n"
"%@\n"
"%@\n"
"\n"
"\n"
"\n",str1,str2,str3,str4];
NSLog(soapMsg);
NSURL *url = [NSURL URLWithString:@"http://192.168.0.218:84/WebServiceCustomerByAmit/Service.asmx?op=InsertCustomerInformation"];
NSLog(@"url. . . .%@", url);
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSLog(@"req....%@", req);
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
NSLog(@"msgLength. . .%@", msgLength);
[req setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req setValue:@"http://tempuri.org/InsertCustomerInformation" forHTTPHeaderField:@"SOAPAction"];
[req setValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"req....%@", req);
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
if(!response){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Failed to Connect to the Internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else{
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Connection Successful" message:@"Connected to the Internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert1 show];
[alert1 release];
}
}
在gdb中:
2011-04-13 18:40:36.137 uploadToWeb[6018:20b] strings.....ketan
2011-04-13 18:40:36.138 uploadToWeb[6018:20b] ketan
2011-04-13 18:40:36.146 uploadToWeb[6018:20b] ?xml version="1.0" encoding="utf-8"?>
soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
ketan
NSr
9463952542
macos
2011-04-13 18:40:36.148 uploadToWeb[6018:20b] url. . . .http://192.168.0.218:84/WebServiceCustomerByAmit/Service.asmx?op=InsertCustomerInformation
2011-04-13 18:40:36.148 uploadToWeb[6018:20b] req....
2011-04-13 18:40:36.148 uploadToWeb[6018:20b] msgLength. . .430
2011-04-13 18:40:36.149 uploadToWeb[6018:20b] req....
网络服务:
1 回答
使用像Charles这样的HTTP代理来查明您的请求是否实际正确形成 .