【发布时间】:2023-06-14 06:50:01
【问题描述】:
我正在向 CISCO ISE 发送包含 XML 数据的 Post 请求,但收到以下错误:
400 Bad Request
我在 RestClient(用于 RESTful Web 服务)中检查了我的 XML 文本、标头和身份验证数据,它成功发出了 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
smb 可以告诉我我的 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";
}
【问题讨论】:
-
您实际上并没有使用 REST::Client,即使您
use REST::Client;。你为什么不做my $client = REST::Client->new(...)? -
服务器消息块 (SMB) 与此有什么关系?
标签: xml perl http-post cisco http-status-code-400