我正在向CISCO ISE发送一个带有XML数据的Post请求,我收到以下错误:
400 Bad Request
我已经在RestClient中检查了我的XML文本,标题和身份验证数据(对于RESTful Web服务),它成功发出了Post请求。但是,我的请求是失败了它的目标客户端,我相信我的脚本有问题。
API文档声明我应该具有以下内容:
Method: POST
URI: https://10.10.10.10:9060/ers/config/networkdevice
HTTP 'Content-Type' header:application/vnd.com.cisco.ise.network.networkdevice.1.0+xml; charset=utf-8
HTTP 'Accept' header: application/vnd.com.cisco.ise.network.networkdevice.1.0+xml
可以告诉我,我的XML数据有问题吗?或者这个错误说了什么?
use strict;
use warnings;
use JSON -support_by_pp;
use LWP 5.64;
use LWP::UserAgent;
use MIME::Base64;
use REST::Client;
use IO::Socket::SSL;
use HTTP::Headers;
use HTTP::Request;
use XML::Simple;
#Create a user agent object
my $ua = LWP::UserAgent->new(ssl_opts=> {
SSL_verify_mode => SSL_VERIFY_NONE(),
verify_hostname => 0,
}
);
my $uri='https://10.10.10.10:9060/ers/config/networkdevice/';
my $header = HTTP::Headers->new;
my $req = HTTP::Request->new('POST', $uri);
my $message =('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:networkdevice name="LAB-WLZZ" id="89c7e480-591f-11e4-ac6a b83861d71000" xmlns:ns2="ers.ise.cisco.com" xmlns:ns3="network.ers.ise.cisco.com">
<authenticationSettings>
<enableKeyWrap>false</enableKeyWrap>
<keyInputFormat>ASCII</keyInputFormat>
<networkProtocol>RADIUS</networkProtocol>
<radiusSharedSecret>******</radiusSharedSecret>
</authenticationSettings>
<NetworkDeviceIPList>
<NetworkDeviceIP>
<ipaddress>9.9.9.9</ipaddress>
<mask>21</mask>
</NetworkDeviceIP>
</NetworkDeviceIPList>
<NetworkDeviceGroupList>
<NetworkDeviceGroup>Location</NetworkDeviceGroup>
<NetworkDeviceGroup>DeviceType</NetworkDeviceGroup>
</NetworkDeviceGroupList>
</ns3:networkdevice>')
;
$req->header('Accept'=>'application/vnd.com.cisco.ise.network.networkdevice.1.0+xml');
$req->header('Content-Type'=>'application/vnd.com.cisco.ise.network.networkdevice.1.0+xml');
$req->content($message);
$req->content_type("charset=utf-8");
$req-> authorization_basic("user", "user");
#Pass request to the user agent and get a response back
my $res = $ua->request($req);
#Check the outcome of the response
if ($res->is_success) {
print $res->status_line, "n";
} else {
print $res->status_line, "n";
}
答案 0 :(得分:4)
您正在使用
将Content-Type标头设置为charset=utf-8
$req->content_type("charset=utf-8");
此替换标题的先前值
application/vnd.com.cisco.ise.network.networkdevice.1.0+xml
与
charset=utf-8
你应该做
$req->content_type(
'application/vnd.com.cisco.ise.network.networkdevice.1.0+xml; charset=utf-8'
);
您也可以像这样构建您的请求:
my $req = HTTP::Request->new('POST', $uri, [
Accept => 'application/vnd.com.cisco.ise.network.networkdevice.1.0+xml',
'Content-Type' => 'application/vnd.com.cisco.ise.network.networkdevice.1.0+xml; charset=utf-8'
], $message);