我試圖在Linksys EA4500 AP中配置無線設置(如將ssid設置爲「vinoth」通道爲「1」)。我可以使用wireshark看到下面的POST消息。在POST中對JSON的HTTP POST請求
[email protected]@!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個鏈接的查詢。
謝謝, Vinoth
我想張貼我的代碼在我的問題,但它說很多indendation約束,所以我刪除它。 – user3441116
可能是Referer頭部?你的代碼中沒有它... – gangabass
什麼應該是referer頭?我看到了該行動訊息的兩個鏈接。你能告訴我如何解析它? – user3441116