使用 NSUrlrequest 来自 .net Web 服务器的不同响应
我正在从 .net Web 服务器获取数据,如下所示。
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GenericAndroidMethodResponse xmlns="Mortgage"><GenericAndroidMethodResult><NewDataSet>
<Table>
<LoanOfficerID>3581</LoanOfficerID>
<FirstName>Venkat</FirstName>
<LastName>Sreenu</LastName>
<Address1>d</Address1>
<City>d</City>
<State>Alabama</State>
<WorkPhone>19999999999</WorkPhone>
<Country>United States</Country>
<EmailAddress>[email protected]</EmailAddress>
<companyName>ensisinfo</companyName>
<CompanyURL>www.ensisinfo.com</CompanyURL>
</Table>
</NewDataSet></GenericAndroidMethodResult></GenericAndroidMethodResponse></soap:Body></soap:Envelope>
但我通过传递 xml 参数和方法名称在浏览器中进行测试,我得到这样的结果。
<NewDataSet> <Table> <LoanOfficerID>3581</LoanOfficerID> <FirstName>Venkat</FirstName> <LastName>Sreenu</LastName> <Address1>d</Address1> <City>d</City> <State>Alabama</State> <WorkPhone>19999999999</WorkPhone> <Country>United States</Country> <EmailAddress>[email protected]</EmailAddress> <companyName>ensisinfo</companyName> <CompanyURL>www.ensisinfo.com</CompanyURL> </Table> </NewDataSet>
我正在使用 NSUrlRequest
NSURL *url = [NSURL URLWithString:@"http://173.31.193.92/MobileGenericWebservice/GenericWebService.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"Mortgage/GenericAndroidMethod" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
为什么会出现这样的情况?
I am getting the data from .net web server like this.
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GenericAndroidMethodResponse xmlns="Mortgage"><GenericAndroidMethodResult><NewDataSet>
<Table>
<LoanOfficerID>3581</LoanOfficerID>
<FirstName>Venkat</FirstName>
<LastName>Sreenu</LastName>
<Address1>d</Address1>
<City>d</City>
<State>Alabama</State>
<WorkPhone>19999999999</WorkPhone>
<Country>United States</Country>
<EmailAddress>[email protected]</EmailAddress>
<companyName>ensisinfo</companyName>
<CompanyURL>www.ensisinfo.com</CompanyURL>
</Table>
</NewDataSet></GenericAndroidMethodResult></GenericAndroidMethodResponse></soap:Body></soap:Envelope>
But I test in browser by passing xml parameters and method name I am getting like this.
<NewDataSet> <Table> <LoanOfficerID>3581</LoanOfficerID> <FirstName>Venkat</FirstName> <LastName>Sreenu</LastName> <Address1>d</Address1> <City>d</City> <State>Alabama</State> <WorkPhone>19999999999</WorkPhone> <Country>United States</Country> <EmailAddress>[email protected]</EmailAddress> <companyName>ensisinfo</companyName> <CompanyURL>www.ensisinfo.com</CompanyURL> </Table> </NewDataSet>
I am using NSUrlRequest
NSURL *url = [NSURL URLWithString:@"http://173.31.193.92/MobileGenericWebservice/GenericWebService.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"Mortgage/GenericAndroidMethod" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
why I am getting like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 XML 中,所有这些
<
和其他代码都像您的示例中那样可见吗?如果是,则整个元素将被解析为
节点中的一个巨大字符串。In the XML are all of those
<
and other codes visible like in your example?If they are then the entire element is just getting parsed as one, giant string that is in the
<GenericAndroidMethodResult>
node.告诉你的 .NET 人员修复它。您得到的不是有效的 XML。
Tell your .NET guy to fix it. What you are getting is not a valid XML.