2011-09-05 64 views
5

我如下調用Web服務:解析器錯誤錯誤域= NSXMLParserErrorDomain代碼= 4「操作無法完成。」

-(void)verifyEmailAndPasswordWebservices 
{  
NSString *MD5Password = [ self MD5]; 
NSLog(@"text field password %@",txt_Password.text); 
NSLog(@"converted password %@",MD5Password);  

NSString *soapMsg =[NSString stringWithFormat: 
        @"<?xml version=\"1.0\" encoding=\"utf-8\"?>" 
        "<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns=\"http://php:8393/includes/webservice\">" 
        "<SOAP-ENV:Body>" 
        "<ns1:LoginUserRequest xmlns:ns1=\"http://schemas.xmlsoap.org/soap/envelope/\">"       
        "<email xsi:type=\"xsd:string\">%@</email>" 
        "<pass xsi:type=\"xsd:string\">%@</pass>"     
        "</ns1:LoginUserRequest>" 
        "</SOAP-ENV:Body>" 
        "</SOAP-ENV:Envelope>",txt_EmailOrMobile.text,MD5Password]; 



//---print it to the Debugger Console for verification--- 
NSLog(@"soapMsg..........%@",soapMsg); 

NSURL *url = [NSURL URLWithString:@"http://10.0.0.115:8393/includes/webservice/login1.php"]; 
req = [NSMutableURLRequest requestWithURL:url]; 

//---set the headers--- 

NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]]; 
[req addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[req addValue:@"http://10.0.0.115/includes/webservice/login1.php/LoginUser" forHTTPHeaderField:@"SoapAction"]; 
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 

//---set the HTTP method and body--- 

[req setHTTPMethod:@"POST"]; 
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]]; 

// [activityIndicator startAnimating]; 

conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 
if (conn) 
{ 
    webData = [[NSMutableData data] retain]; 
} 
} 

當我把它給我下面的錯誤響應:

DONE。接收的字節:422 顯示XML(空) 分析器錯誤錯誤域= NSXMLParserErrorDomain代碼= 4「的操作無法完成(NSXMLParserErrorDomain錯誤4)。」

我已經搜查了不少的互聯網。但無法找到任何東西。請任何幫助。

回答

8

NSXMLParserErrorDomain error 4意味着XML解析器被賦予一個空文檔。這表明輸入或者是null,或者在它被提供給解析器之前設法改變它。

我有更好的看看你的代碼。問題不在於你沒有得到迴應。只是你不等它而已。您發送的請求是異步的,但您試圖直接填寫webData變量(即同步)。

+0

這是否意味着我必須和網絡服務人員說話以檢查他正在發送的響應?同樣的Web服務正在Android應用程序中工作。 – Rushi

+0

我已經添加到我的答案,請讓我知道如果這確實是問題。 –

+0

我已從我的代碼中刪除以下行: if(conn) webData = [[NSMutableData data] retain]; } 現在即時通訊在下面的函數填充weData變量: - (無效)連接:(NSURLConnection的*)連接didReceiveData:(NSData的*)數據 它沒有更多的給NSXMLParserErrorDomain錯誤4.但現在已經給下面的錯誤。 分析器錯誤錯誤域= NSXMLParserErrorDomain代碼= 5 「的操作無法完成(NSXMLParserErrorDomain錯誤5)。」 im使用PHP web服務 – Rushi

1

另一個可能的共振可能是沒有根標籤。 例子:一個XML數據是這樣--->


2011-12-22

<days_remaining> 
      0 
</days_remaining> 
0

嘗試在你的編碼方法的代碼

NSString *theXML = [[NSString alloc] initWithBytes: [_responseData mutableBytes] length:[_responseData length] encoding:NSUTF8StringEncoding]; 
相關問題