解析器错误错误域= NSXMLParserErrorDomain代码= 4“操作无法完成。”

解析器错误错误域= NSXMLParserErrorDomain代码= 4“操作无法完成。”

问题描述:

我如下调用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)。”

我已经搜查了不少的互联网。但无法找到任何东西。请任何帮助。

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

另一个可能的共振可能是没有根标签。 例子:一个XML数据是这样--->


2011-12-22

<days_remaining> 
      0 
</days_remaining> 

尝试在你的编码方法的代码

NSString *theXML = [[NSString alloc] initWithBytes: [_responseData mutableBytes] length:[_responseData length] encoding:NSUTF8StringEncoding];