解析器错误错误域 = 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];
}
}
当我收到响应时,它给出以下错误:
完成。接收字节:422 显示 XML(空) 解析器错误错误域= NSXMLParserErrorDomain代码= 4“操作无法完成。(NSXMLParserErrorDomain错误4。)”
我在互联网上搜索了很多。但找不到任何东西。请对此有任何帮助。
I am calling a web service as below:
-(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];
}
}
When i get the response it give me following error:
DONE. Received Bytes: 422
shows the XML (null)
Parser error Error Domain=NSXMLParserErrorDomain Code=4 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 4.)"
I've searched quite a bit on the internet. But not able to find anything. Any help on this please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NSXMLParserErrorDomain 错误 4
表示向 XML 解析器提供了一个空文档。这对我来说意味着输入要么为空,要么您在将其提供给解析器之前设法更改了它。我更好地看了你的代码。问题不在于您没有得到回复。只是你没有等到它。您发送的请求是异步的,但您试图立即(即同步)填充您的
webData
变量。NSXMLParserErrorDomain error 4
means that the XML parser was given an empty document. That suggests to me that the input was either null, or you've managed to change it before it's given to the parser.I had a better look at your code. The problem isn't that you aren't getting a response. It's just that you're not waiting for it. The request you sent is asynchronous, but you're trying to fill your
webData
variable straight away (i.e. synchronously).另一个可能的原因可能是没有根标签。
例子:像这样的xml数据--->
2011-12-22
Another possible reson might be that there is no root tag.
example:A xml data like this--->
2011-12-22
在您的编码方法上尝试此代码
Try this code on your encoding method