分析器错误错误域= NSXMLParserErrorDomain代码= 4"无法完成操作."

Rus*_*shi 5 xml web-services objective-c nsxmlparser ios

我正在调用以下Web服务:

-(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];
}   
}
Run Code Online (Sandbox Code Playgroud)

当我收到回复时,它会给我以下错误:

DONE.Received Bytes:422显示XML(null)Parser错误Error Domain = NSXMLParserErrorDomain Code = 4"操作无法完成.(NSXMLParserErrorDomain error 4.)"

我在互联网上搜索了很多.但是找不到任何东西.请帮忙.

Jam*_*ter 8

NSXMLParserErrorDomain error 4意味着XML解析器被赋予了一个空文档.这告诉我输入是null,或者你已经设法在它被提供给解析器之前改变它.

我更好地查看了您的代码.问题不是你没有得到回应.只是你不是在等它.您发送的请求是异步的,但您正在尝试立即填充webData变量(即同步).

  • 请注意,如果您看到这样的错误,可以在Xcode中点击Cmd + Shift + o,输入"NSXMLParserErrorDomain"并直接跳转到类型定义(希望是)所有错误代码定义. (3认同)