unable to get parameter in webservice
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
get values from text field to webservice
我以前也贴过类似的问题,但没有得到适当的帮助!我在重复。我正在将参数从textfield上载到Web服务。一切正常,但我无法检索WebService中的值。请帮助!!这是我的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(textView1.text); NSString *soapMsg = [[NSString alloc] initWithFormat:@"?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/"> " "" " " "%@ " "%@ " "%@ " "%@ " " " " " " ",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中:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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.... |
网络服务:。
使用像charles这样的HTTP代理来确定请求的格式是否正确。