这是我的代码:
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
NSURL *url = [NSURL URLWithString:urlString];
theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest addValue:@"gzip" forHTTPHeaderField:@"accept-encoding"];
[theRequest addValue:@"en-us" forHTTPHeaderField:@"accept-language"];
[theRequest addValue:@"[application/soap+xml, application/dime, multipart/related, text/*]" forHTTPHeaderField:@"Accept"];
//[theRequest addValue:@"user_agent" forHTTPHeaderField:@"user-agent"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [requestMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"REQUEST\n%@", theRequest);
webConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
在connectionDidFinishLoading中,我写了这个:
NSString *theXML = [[NSString alloc] initWithBytes: [dataFromWebService mutableBytes] length:[dataFromWebService length] encoding:NSUTF8StringEncoding];
NSLog(@"XML:\n%@", theXML);
现在,当我运行代码时,我收到一些错误响应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Error reading XMLStreamReader.</faultstring></soap:Fault></soap:Body></soap:Envelope>
为什么我收到此错误而非实际回复?在app端或服务器端是错误吗?
编辑:这是SOAP消息:
Content-Type: text/xml; charset=utf-8
Headers: {Accept=[application/soap+xml, application/dime, multipart/related, text/*], cache-control=[no-cache], Content-Length=[407], content-type=[text/xml; charset=utf-8], host=[172.16.253.74:8080], pragma=[no-cache], SOAPAction=["urn:Login"], user-agent=[Axis/1.4]}
Payload: <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><login xmlns="http://tilloperations.services.mpos.tcs.com/"><arg0 xmlns=""><password>Posadmin@1</password><userId>posadmin</userId></arg0></login></soapenv:Body></soapenv:Envelope>
我将有效负载部分作为SOAP消息'requestMessage'传递。
答案 0 :(得分:0)
我意识到这是一个老问题,但是对于记录来说,问题几乎肯定是arg0
元素上的空白默认命名空间声明。
引自Namespaces in XML规范的第2.2节:
“空字符串虽然是合法的URI引用,但不能使用 作为命名空间名称。“