首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解析器错误,无法完成“Domain=NSXMLParserErrorDomain Code=4”。

解析器错误,无法完成“Domain=NSXMLParserErrorDomain Code=4”。
EN

Stack Overflow用户
提问于 2011-09-05 15:11:56
回答 3查看 9.4K关注 0票数 6

我正在调用一个web服务,如下所示:

代码语言:javascript
复制
-(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 (null)解析器错误Domain=NSXMLParserErrorDomain Code=4“Domain=NSXMLParserErrorDomain Code=4‘t confied. (NSXMLParserErrorDomain error 4.)”

我在互联网上搜索了很多。但什么也找不到。有什么需要帮忙的吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-09-05 15:19:27

NSXMLParserErrorDomain error 4意味着为XML解析器提供了一个空文档。对我来说,这表明输入要么是空的,要么是在提供给解析器之前您已经设法更改了它。

我更仔细地看过你的代码。问题不是你得不到回应。只是你并不是在等它。您发送的请求是异步的,但您正在尝试直接(即同步)填充您的webData变量。

票数 8
EN

Stack Overflow用户

发布于 2012-01-03 15:31:34

另一个可能的原因可能是没有根标签。示例:像这样的xml数据->

代码语言:javascript
复制
                           2011-12-22     
代码语言:javascript
复制
<days_remaining>
            0
</days_remaining>
票数 1
EN

Stack Overflow用户

发布于 2012-02-23 22:03:44

在您的编码方法上尝试此代码

代码语言:javascript
复制
NSString *theXML = [[NSString alloc] initWithBytes: [_responseData mutableBytes] length:[_responseData length] encoding:NSUTF8StringEncoding];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7304850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档