英文:
Twilio returning 400 Bad request
问题
以下是您要求的翻译:
我正在从Java代码执行Twilio短信API的curl命令。以下是CURL命令,我正在以JSON格式发送数据:
curl, -X, POST, https://api.twilio.com/2010-04-01/Accounts/[AccountSID]/Messages.json, -H, Content-type:application/json, -d, {"Body":"This is First Message","Form":"+120XXXXX216","To":"+91XXXXXX476"}, -u, [AccountSID]:[AuthToken]
但是我得到了Twilio的错误响应:
{
"code": 21602,
"message": "Message body is required.",
"more_info": "https://www.twilio.com/docs/errors/21602",
"status": 400
}
我的命令上有什么问题吗?
英文:
I am executing a curl command for Twilio SMS API from Java Code. Below is the CURL command and I and sending data in JSON
curl, -X, POST, https://api.twilio.com/2010-04-01/Accounts/[AccountSID]/Messages.json, -H, Content-type:application/json, -d, {"Body":"This is First Message","Form":"+120XXXXX216","To":"+91XXXXXX476"}, -u, [AccountSID]:[AuthToken]
But I am getting error response twilio
{
"code": 21602,
"message": "Message body is required.",
"more_info": "https://www.twilio.com/docs/errors/21602",
"status": 400
}
Is there anything on my command?
答案1
得分: -1
你是否阅读了Twilio发送短信指南页面上关于cURL代码示例的内容?
- 你似乎插入了许多随意的逗号(
,
)。不清楚你为什么这样做,但在Twilio的文档(上述链接)中并未提到要使用这些逗号。如果这与你的Java实现有关,你应该提供关于它的额外上下文(即,代码中如何执行调用)。 - 此外,在所链接的示例中,URL参数是使用
--data-urlencode
开关发送的,该开关比-d
开关执行更多的URL编码。 - 虽然与你目前收到的错误消息没有直接关系,但你还尝试传递一个名为
Form
的参数,显然你是想使用From
。
试试这个:
curl -X POST https://api.twilio.com/2010-04-01/Accounts/[AccountSID]/Messages.json --data-urlencode "Body=这是第一条消息" --data-urlencode "From=+120XXXXX216" --data-urlencode "To=+91XXXXXX476" -u [AccountSID]:[AuthToken]
英文:
Have you read over the sample cURL code on the Sending Messages - Twilio page?
- You seem to have inserted a number of arbitrary commas (
,
). Not sure why you've done this, but nowhere in Twilio's documentation (linked above) does it mention to use these. If this is related to your Java implementation of this command, you should provide additional context around that (i.e., how the invocation is being performed in your code). - Also in the example linked, the URL parameters are sent using the
--data-urlencode
switch, which does a bit more URL encoding than the-d
switch does. - While not directly related to the error message you're currently receiving, you're also attempting to pass a parameter called
Form
, when it's evident you meantFrom
.
Try this:
curl -X POST https://api.twilio.com/2010-04-01/Accounts/[AccountSID]/Messages.json --data-urlencode "Body=This is First Message" --data-urlencode "From=+120XXXXX216" --data-urlencode "To=+91XXXXXX476" -u [AccountSID]:[AuthToken]
专注分享java语言的经验与见解,让所有开发者获益!
评论