首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS中的NDFD SOAP请求

iOS中的NDFD SOAP请求
EN

Stack Overflow用户
提问于 2012-02-20 06:57:46
回答 1查看 1K关注 0票数 1

我正在尝试使用SOAP请求访问国家数字预报数据库(NDFD)中的每日天气。SOAP URL为

代码语言:javascript
复制
http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php

NDFDgenByDay()的Soap操作是

代码语言:javascript
复制
http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgenByDay. 

当我发送请求时,我收到的xml指示发生了错误,我相信这与我的HTTP头有关。错误响应如下所示。

代码语言:javascript
复制
 <?xml version="1.0" encoding="ISO-8859-1"?><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/">
<SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">SERVER</faultcode>    <faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">format needs to be either 24 hourly or 12 hourly</faultstring><detail xsi:type="xsd:string">input     format was &quot;&quot;</detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

此错误对象为"format“值,但如下所示,我的xml符合。

我在iOS/Obj-C中发送请求,如下所示:

代码语言:javascript
复制
    NSString *path = [[NSBundle mainBundle] pathForResource:@"soapRequest" ofType:@"xml"];
    NSString *soapContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];

    NSURL *url = [NSURL URLWithString:kWeatherSOAP_URL];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapContent length]];

    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue:@"NDFDgenByDay" forHTTPHeaderField:@"Name"];
    [theRequest addValue:@"ndfdXMLBinding" forHTTPHeaderField:@"Binding"];
    [theRequest addValue:@"http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php" forHTTPHeaderField:@"Endpoint"];
    [theRequest addValue: @"http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgenByDay" forHTTPHeaderField:@"SoapAction"];
    [theRequest addValue:@"rpc" forHTTPHeaderField:@"Style"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapContent dataUsingEncoding:NSUTF8StringEncoding]];

    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if (theConnection)
        receivedData = [NSMutableData data];
    else
        NSLog(@"theConnection is NULL");

soapRequest.xml看起来像什么

代码语言:javascript
复制
<SOAP-ENV:Envelope 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/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
    <ns6244:NDFDgenByDay xmlns:ns6244="uri:DWMLgenByDay">
        <latitude xsi:type="xsd:string">38.99</latitude>
        <longitude xsi:type="xsd:string">-77.01</longitude>
        <startDate xsi:type="xsd:string">2012-03-12</startDate>
        <numDays xsi:type="xsd:string">7</numDays>
        <format xsi:type="xsd:string">24 hourly</format>
    </ns6244:NDFDgenByDay>
</SOAP-ENV:Body>

我相信soapRequest.xml是正确的,因为它在NDFD网站上是以sample code的形式发布的。但是,我不知道设置HTTP标头的正确方法。如果有人对此很熟悉,或者知道问题出在哪里,请帮助我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-07 18:06:28

我通过将soapRequest.xml更改为ff来运行您的程序:

代码语言:javascript
复制
<?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/">
    <SOAP-ENV:Body>
        <ns6244:NDFDgenByDay xmlns:ns6244="uri:DWMLgenByDay">
            <latitude xsi:type="xsd:decimal">38.99</latitude>
            <longitude xsi:type="xsd:decimal">-77.01</longitude>
            <startDate xsi:type="xsd:date">2012-08-07</startDate>
            <numDays xsi:type="xsd:integer">7</numDays>
            <Unit xsi:type="xsd:string">m</Unit>
            <format xsi:type="xsd:string">24 hourly</format>
        </ns6244:NDFDgenByDay>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9354145

复制
相关文章

相似问题

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