如何解决无法通过 twilio 发送短信,出现 400 错误
我正在尝试使用 Java 代码中的 HttpEntity 通过 Twilio 发送短信。我收到 400 Bad Request 没有详细信息。回复如下。
[<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>openresty</center>
</body>
</html>]
下面是我用来发送请求的代码。 Postman 的请求成功。我不能使用 Java SDK,必须使用 RestTemplate。
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.add("route-to-back-end-endpoint","https://api.twilio.com/2010-04-01/Accounts/xxx/Messages.json");
MultiValueMap<String,String> map = new LinkedMultiValueMap<>();
map.add("To","+91*******");
map.add("From","+1******");
map.add("Body","Try try try");
HttpEntity<MultiValueMap<String,String>> entity = new HttpEntity<>(map,headers);
String response = null;
try {
restTemplateSsl.getInterceptors().add(new BasicAuthenticationInterceptor("xxx","yyy"));
response = restTemplateSsl.postForObject("Internal Xml Gateway Link",entity,String.class);
} catch (Exception e) {
e.printStackTrace();
log.error("Exception : {} ",e.getMessage());
}
log.info("Response Received :{}",response);
return response;
使用 Twilio 验证成功。所以没有身份验证问题。我不确定请求中到底有什么问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。