【发布时间】:2014-03-27 01:02:11
【问题描述】:
我正在尝试在 Linksys EA4500 AP 中配置无线设置(例如将 ssid 设置为“vinoth”通道为“1”)。我可以使用 wireshark 看到下面的 POST 消息。
3E@@!dPzY+2K
SPOST /JNAP/ HTTP/1.1
Host: 192.168.1.1
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:22.0) Gecko/20100101 Firefox/22.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
X-JNAP-Action: http:cisco.com/jnap/core/Transaction
X-JNAP-Authorization: Basic YWRtaW46YWRtaW4=
X-Requested-With: XMLHttpRequest
Referer: http:/cisco.com/ <<<<==== routerip
Content-Length: 474
Cookie: initial-tab=; ui-proxy-path=local; admin-auth=Basic%20YWRtaW46YWRtaW4%3D; current-applet=7B1F462B-1A78-4AF6-8FBB-0C221703BEA4
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
[{"action":"http:/cisco.com/jnap/wirelessap/SetRadioSettings","request":{"radios":[{"radioID":"RADIO_2.4GHz","settings":{"isEnabled":true,"mode":"802.11bgn","ssid":"vinoth","broadcastSSID":true,"channelWidth":"Auto","channel":1,"security":"None"}}]}},{"action":"http://cisco.com/jnap/guestnetwork/SetGuestNetworkSettings","request":{"isGuestNetworkEnabled":false,"guestSSID":"vinoth-guest","guestPassword":"BeMyGuest","maxSimultaneousGuests":5,"broadcastGuestSSID":false}}]
我尝试使用 Perl 自动执行上述操作,但没有成功。由于我是这个 JSON 页面的新手,所以我不知道要发送的 POST 消息到底是如何发送的。
我为 $json 保留的内容是
'{"action":"http:/cisco.com/jnap/wirelessap/SetRadioSettings",' .
'"request":{"radios":{"radioID":"RADIO_2.4GHz","settings":'.'{"isEnabled":true,"mode":"802.11bgn","ssid":"vinoth212","broadcastSSID":true,"channelWidth":"Auto","channel":1,"security":"None"}}}},{"action":"http://cisco.com/jnap/guestnetwork/SetGuestNetworkSettings",' .
'"request":{"isGuestNetworkEnabled":false,"guestSSID":"vinoth-guest","guestPassword":"BeMyGuest","maxSimultaneousGuests":5,"broadcastGuestSSID":false}}';
和代码:
use strict;
use warnings;
use LWP;
my $ua = LWP::UserAgent->new;
my $ip = $self->{ip};
my $url = "http://$ip/";
my $json = "";
my $req = HTTP::Request->new(POST=>$url);
$req->header('content-type' => 'application/json');
$req->authorization_basic("admin", "admin");
$req->content($json);
下面是检查请求状态的代码
my $res = $ua->request($req);
if ($res->is_success) {
my $message = $res->decoded_content;
print "received the message";
} else {
print "HTTP get code: ", $res->code, "\n";
print "HTTP get: msg: ", $res->message, "\n";
}
请帮我解决这个问题。期待您的宝贵回复。
P.S:在 Wireshark Post 消息中,链接不正确,因为我无法发布超过 2 个链接的查询。
谢谢, 维诺特
【问题讨论】:
-
我试图在我的问题中发布我的代码,但它说很多缩进限制,所以我删除了它。
-
可能是Referer标头?您的代码中没有它...
-
referer 标头应该是什么?我在该操作消息上看到两个链接。你能告诉我如何解析它吗??
-
Referer: http:/cisco.com/ <<<<==== routerip与 Wireshark 日志中的相同 -
我试过这个。我的 $req = HTTP::Request->new(POST=>"192.168.1.1/"); $req->header(content-type=>"application/json";$req->content($json); 我的 $ res = $ua->request($req); 并且 $res->is_success 的结果返回“Internal Server Error”和错误码“500”
标签: json perl httprequest lwp-useragent