我正在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;
答案 0 :(得分: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>