我正打算打个电话。我能够成功拨打电话,但是它说:"抱歉,发生了一些应用程序错误"。它可能是响应XML中的一个问题。
以下是拨打电话的代码:
@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();
}
我不确定是什么问题。请帮忙。提前谢谢。
答案 0 :(得分:3)
问题是方法=RequestMethod.GET
,应该是POST。
您可以在THIS中详细说明要使用的方法。建议使用POST,这是默认设置。
在此示例中,Twilio将POST到http://demo.twilio.com/docs/voice.xml
以获取TwiML来处理呼叫:
// Build a filter for the CallList
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
params.add(new BasicNameValuePair("To", "client:tommy"));
params.add(new BasicNameValuePair("From", "+14158675309"));
但是在这里Twilio会向http://demo.twilio.com/docs/voice.xml
发送一个GET请求以获取TwiML来处理该呼叫。
// Build a filter for the CallList
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
params.add(new BasicNameValuePair("To", "+14155551212"));
params.add(new BasicNameValuePair("SendDigits", "1234#"));
params.add(new BasicNameValuePair("From", "+18668675309"));
params.add(new BasicNameValuePair("Method", "GET"));