我正在尝试拨打电话。我能够成功拨打电话,但它说:“对不起,发生了一些应用程序错误”。这可能是响应XML中的一个问题。TwiMLResponse with dial verb in java
以下是拨打电话代码:
@RequestMapping(value = "/makeCall", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
String makeCall(@RequestBody TwilRequest twilRequest, HttpServletRequest request) {
....
Map<String, String> params = new HashMap<String, String>();
params.put("From", CallerID);
params.put("To", addPulsIfNot(twilRequest.getToPhone()));
params.put(
"Url", "http://example.com/ws/twil/voiceResponse?phone=9198989...");
.....
}
下面是调用响应服务,并返回XML响应:
@RequestMapping(value = "/voiceResponse", method = RequestMethod.GET)
public @ResponseBody String voiceResponse(HttpServletRequest request,
HttpServletResponse response) throws IOException {
TwiMLResponse twiml = new TwiMLResponse();
Dial dial = new Dial(addPulsIfNot(phone));
try {
dial.append(client);
twiml.append(dial);
} catch (TwiMLException e) {
e.printStackTrace();
}
response.setContentType("Application/xml");
return twiml.toXML();
}
我不知道什么是错的。请帮忙。提前致谢。
您是在本地运行还是在服务器上运行?你可以检查Twilio仪表板的[Monitor](https://www.twilio.com/user/account/monitor/alerts)部分,看看错误究竟是什么? – philnash
谢谢philnash,现在它的工作问题是method = RequestMethod.GET,它应该是POST。它可以帮助他人。 – Dharmraj
啊哈!实际上,您可以将[您要在API中使用的方法]设置为(https://www.twilio.com/docs/api/rest/making-calls#post-parameters-optional)。不过,我们确实推荐使用POST。很高兴它现在都适合你。 – philnash