我無法使這項工作我不斷收到一個400錯誤的請求響應發送JSON請求。任何幫助非常感謝,因爲這是我第一次嘗試編碼perl和使用JSON。我不得不刪除一些敏感數據,因爲這是工作。這個腳本的要點是簡單地點擊通過JSON發送POST數據的URL並打印響應。孤男寡女在Perl
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON;
my $ua = LWP::UserAgent->new;
my $req = POST 'URL IS HERE';
my $res = $ua->request($req);
my $json = '{"warehouseId": "ID",
"tagMap":
{"cameraId":["Name of camera"]
},
"searchStartTimeStamp": 0,
"searchEndTimeStamp": 100000000000000,
"pageSize": 1,
"client":
{"id": "username",
"type": "person"}
}';
$req->header('Content-Type' => 'application/json');
$req->content($json);
if ($res->is_success) {
print $req->content($json);
print $res->content;
} else {
print $res->status_line . "\n";
}
exit 0;
這是從腳本輸出「400錯誤的請求」 – root