再次嘗試使用soap方法,但是這次我下載了charles並觀察了從我的代碼創建的請求。 Chales顯示「無法解析數據(org.xml.sax.saxparser例外:內容是不是在序言允許)」將參數傳遞給Web服務工作代碼
這裏是我的代碼:
NSString *soapMsg = [[NSString alloc] initWithFormat:@"\n" "\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 addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [req addValue: @"http://tempuri.org/InsertCustomerInformation" forHTTPHeaderField:@"SOAPAction"]; [req addValue: 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]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; if(theConnection) { //webData = [[NSMutableData data] retain]; NSLog(@"theConnection is OK"); } else { NSLog(@"theConnection is NULL"); } 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]; } }
幫助!提前致謝!!
嘗試在SOAP URL的結尾處刪除op = InsertsCustomerInformation,如果在服務中創建斷點構造函數是否會收到任何信號? – 2011-04-07 13:01:16
請將您的代碼和xml複製並粘貼到問題中。不是他們的圖像。 – Anna 2011-04-07 13:02:19
@anna:實際上代碼有標籤並且顯示不正確。這就是爲什麼我附上圖像。 – Ketan 2011-04-07 13:08:28