SendHub的文档状态发送包含数据和json数据的帖子。 这是他们给出的卷曲例子 尝试使用perl和LWP::User代理执行此操作但收到错误请求或未经授权的
我是否正确编码了请求?
curl -H“Content-Type:application / json”-X POST --data'{“contacts”:[1111],“text”:“Testing”}'https://api.sendhub.com/v1/messages/?username
require LWP::UserAgent;
my $uri = 'https://api.sendhub.com/v1/messages/?username=MY_USERNAME\&api_key=MY_KEY_NUMBER';
my $json = '{"contacts":[18005551212],"text":"testing"}';
my $req = HTTP::Request->new('POST',$uri);
$req->header('Content-Type' => 'application/json');
$req->content($json);
my $lwp = LWP::UserAgent->new;
my $response=$lwp->request($req);
if ($response->is_success) {
print $response->decoded_content;
}
else {
die $response->status_line;
}
答案 0 :(得分:1)
看起来基本上没问题。
网址中&符号之前的反斜杠是什么?
'https://api.sendhub.com/v1/messages/?username=MY_USERNAME\&api_key=MY_KEY_NUMBER'
我认为应该是
'https://api.sendhub.com/v1/messages/?username=MY_USERNAME&api_key=MY_KEY_NUMBER'
但如果您收到401 Unauthorized
,那么请求很可能是正确的,但用户名和密钥错误。