使用 NSUrlrequest 来自 .net Web 服务器的不同响应

发布于 2024-10-19 09:54:56 字数 2867 浏览 2 评论 0原文

我正在从 .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>&lt;NewDataSet&gt;
  &lt;Table&gt;
    &lt;LoanOfficerID&gt;3581&lt;/LoanOfficerID&gt;
    &lt;FirstName&gt;Venkat&lt;/FirstName&gt;
    &lt;LastName&gt;Sreenu&lt;/LastName&gt;
    &lt;Address1&gt;d&lt;/Address1&gt;
    &lt;City&gt;d&lt;/City&gt;
    &lt;State&gt;Alabama&lt;/State&gt;
    &lt;WorkPhone&gt;19999999999&lt;/WorkPhone&gt;
    &lt;Country&gt;United States&lt;/Country&gt;
    &lt;EmailAddress&gt;[email protected]&lt;/EmailAddress&gt;
    &lt;companyName&gt;ensisinfo&lt;/companyName&gt;
    &lt;CompanyURL&gt;www.ensisinfo.com&lt;/CompanyURL&gt;
  &lt;/Table&gt;
&lt;/NewDataSet&gt;</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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小苏打饼 2024-10-26 09:54:56

在 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.

高冷爸爸 2024-10-26 09:54:56

告诉你的 .NET 人员修复它。您得到的不是有效的 XML。

Tell your .NET guy to fix it. What you are getting is not a valid XML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文