简体   繁体   English

Perl:服务器无法识别http标头的值

[英]Perl: server did not recognize the value of http header

I'm making my first steps in Perl and I want to consume an existing webservice but it seems that I'm doing something wrong since I keep getting an error "server did not recognize the value of http header". 我正在Perl中迈出第一步,我想使用一个现有的Web服务,但是由于我不断收到错误“服务器无法识别http标头的值”,因此我似乎做错了。 Can anyone help me with this? 谁能帮我这个?

Here's the code: 这是代码:

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;

I could not fix the problem with your soap code. 我无法解决您的肥皂代码的问题。 Luckily the service you use also provides a simple interface you cann access with simple GET or POST requests (as described here ( http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP ) 幸运的是,您使用的服务还提供了一个简单的界面,您无法使用简单的GET或POST请求访问该界面(如此处所述( http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP

So you coud use: 因此,您可以使用:

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

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM