当我向twilio API发送响应时,我正面临415不受支持的媒体类型问题。Twilio API 415不支持的媒体类型错误。错误 - 11200
我将消息发送到使用twilio API一些如下
TwilioRestClient client = new TwilioRestClient(accountSID, authToken);
Account account = client.getAccount();
MessageFactory messageFactory = account.getMessageFactory();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(TO, mobileNumber));
params.add(new BasicNameValuePair(FROM_, from));
params.add(new BasicNameValuePair(BODY, messageBody));
params.add(new BasicNameValuePair(CALL_BACK_URL, callBackUrl));
我配置了callBackUrl为twilio发送到我的系统响应时曾经出现在我的消息的状态的变化。
下面是处理twilio入站响应
@POST
@Path("/callback/inbound/Twilio")
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML,MediaType.TEXT_PLAIN })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response inboundTwilio(@QueryParam("AccountSid") String accountSid,
@QueryParam("MessageSid") String gatewayTxnId,
@QueryParam("MessageStatus") String messageStatus,
@QueryParam("ErrorCode") String errorCode,
@QueryParam("From") String from,
@QueryParam("To") String to,
@Context HttpServletRequest request) throws DateParseException {
Response response = null;
try{
Long startTime = System.currentTimeMillis();
LOGGER.info("In twilio inbound response for gatewayTxnId :: "+gatewayTxnId);
// business logic and processing of twilio inbound handled here and it will return a status object
LOGGER.info("Execution completed in :: "+(System.currentTimeMillis()-startTime));
if (status != null && SUCCESS.equalsIgnoreCase(status)) {
TwiMLResponse twiml = new TwiMLResponse();
Message message = new Message("SUCCESS");
twiml.append(message);
response = Response.status(Response.Status.OK).entity(twiml).build();
} else {
response = Response.status(Response.Status.BAD_REQUEST).build();
}
}catch(Exception e){
LOGGER.error("An error occured in MessageResource while processing inboundTwilio :: ",e.getMessage());
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseUtil.prepareResponse("500",
"Error occoured while processing your request", ExceptionUtils.getStackTrace(e)).toString()).build();
}
return response;
}
处理来自twilio发送响应返回给它。当要求检查我在twilio调试器响应的状态后的代码,它显示失败415媒体不受支持的错误。我无法找到确切的原因。指导我如果有什么是错的
开发基于我的理解从https://www.twilio.com/docs/api/twiml/sms/your_response##标题##
这是一个典型的Twilio入站的样子
请求
URL
/REST /消息/回调/入内/ Twilio?
参数
MESSAGESTATUS发送
APIVERSION 2010-04-01
SMSSID
SMSSTATUS发送
TO 91123456789
来自发件人的
MESSAGESID
ACCOUNTSID
响应对象不是HttpServletResponse。它是javax.ws.rs.core.Response。所以我添加了像这样** Response.status(Response.Status.OK).header(“Content-Type”,“application/xml”)。entity(twiml).build(); **发送内容 - 键入回应。仍然没有运气 – Adithya