问题描述
此问题与使用 Twilio CLIENT 从浏览器直接呼叫电话号码有关。
我想问您是否可以将 request.PHP 替换为 Rest WebService,它返回与request.PHP。
@POST
@Path("directCall")
@Produces({MediaType.APPLICATION_XML})
public String doDirectCall(@Context HttpServletRequest request) {
String tlfCuenta = (String)request.getParameter("Caller_Id");;
String tlfCliente = (String)request.getParameter("To");
String twiml =
"<?xml version='1.0' encoding='UTF-8'?>"
+ "<Response>"
+ " <Dial callerId='" + tlfCuenta + "' record='true'>"
+ " <Number>"
+ tlfCliente
+ " </Number>"
+ " </Dial>"
+ "</Response>";
return twiml;
}
并在 Twilio 控制台 的 REQUEST URL 字段中指向它。
正如我在 Twilio 调试器中看到的那样,Twilio 到达我们的 WebService doDirectCall 方法,但它失败并显示“HTTP 状态代码 415”。
尝试从 https://xxx.yyy.es/avdisws/twilioCallService/directCall 检索内容返回 HTTP 状态代码 415
测试失败,并尝试了一些下一个注释:
@Produces({MediaType.APPLICATION_XML})
@Produces({MediaType.TEXT_PLAIN})
@Produces({MediaType.APPLICATION_JSON})
谢谢!
解决方法
有了这个注释就可以了:
@Consumes({MediaType.APPLICATION_FORM_URLENCODED})
@Produces({MediaType.TEXT_XML})