【问题标题】:Perl: server did not recognize the value of http headerPerl:服务器无法识别 http 标头的值
【发布时间】:2014-10-13 11:06:28
【问题描述】:

我正在 Perl 中迈出第一步,我想使用现有的 web 服务,但我似乎做错了什么,因为我不断收到错误“服务器无法识别 http 标头的值”。谁能帮我解决这个问题?

代码如下:

use warnings;
use strict;
use SOAP::Lite 'trace';

my $soap = SOAP::Lite
    -> uri('http://ws.cdyne.com/WeatherWS/Weather.asmx')
    -> on_action( sub { join '/', 'http://wsf.cdyne.com/WeatherWS/Weather.asmx', $_[1] } )
    -> proxy('http://wsf.cdyne.com/WeatherWS/Weather.asmx');

my $method = SOAP::Data->name('GetCityWeatherByZIP')
->attr({xmlns => 'http://ws.cdyne.com/WeatherWS/'});

my @params = ( SOAP::Data->name(ZIP => 10007));

print $soap->call($method => @params)->result;

【问题讨论】:

    标签: web-services perl soap


    【解决方案1】:

    我无法解决您的肥皂代码问题。 幸运的是,您使用的服务还提供了一个简单的接口,您无法通过简单的 GET 或 POST 请求访问(如此处所述 (http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP)

    所以你可以使用:

    use LWP::Simple;
    my $zip = '10007';
    my $result = get("http://wsf.cdyne.com//WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=$zip");
    print $result;
    

    结果:

    <?xml version="1.0" encoding="utf-8"?>
    <WeatherReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ws.cdyne.com/WeatherWS/">
      <Success>true</Success>
      <ResponseText>City Found</ResponseText>
      <State>NY</State>
      <City>New York</City>
      <WeatherStationCity>White Plains</WeatherStationCity>
      <WeatherID>15</WeatherID>
      <Description>N/A</Description>
      <Temperature>63</Temperature>
      <RelativeHumidity>87</RelativeHumidity>
      <Wind>E7</Wind>
      <Pressure>29.97S</Pressure>
      <Visibility />
      <WindChill />
      <Remarks />
    </WeatherReturn>
    

    【讨论】:

      猜你喜欢
      • 2018-11-16
      • 1970-01-01
      • 1970-01-01
      • 2014-05-06
      • 1970-01-01
      • 1970-01-01
      • 2021-10-17
      • 2014-12-02
      • 2010-09-26
      相关资源
      最近更新 更多