2011-04-07 108 views
2

再次嘗試使用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]; 

    } 
} 


幫助!提前致謝!!

+0

嘗試在SOAP URL的結尾處刪除op = InsertsCustomerInformation,如果在服務中創建斷點構造函數是否會收到任何信號? – 2011-04-07 13:01:16

+3

請將您的代碼和xml複製並粘貼到問題中。不是他們的圖像。 – Anna 2011-04-07 13:02:19

+0

@anna:實際上代碼有標籤並且顯示不正確。這就是爲什麼我附上圖像。 – Ketan 2011-04-07 13:08:28

回答

1

你在問如何在你的項目中包含ASIHTTPRequest,對吧?複製並粘貼到你的項目的文件夾ASIHTTPRequest的文件夾,並在代碼中添加此:

#import "ASIHTTPRequest.h" 

注意ASIHTTPRequest是外部庫,而不是iOS版SDK的一部分。

+0

我在哪裏可以找到ASIHTTPRequest的文件夾? – Ketan 2011-04-14 09:57:36

+0

在網站上。 – pt2ph8 2011-04-14 10:03:10

+0

可以給我發送鏈接嗎? 。實際上我已經下載了壓縮文件,但是當我在項目中添加組和文件下的整個文件夾時,它不工作。這裏是鏈接:http://allseeing-i.com/ASIHTTPRequest/ – Ketan 2011-04-14 10:11:20