首页 文章

Twilio API 415不支持媒体类型错误 . 错误 - 11200

提问于
浏览
2

当我向twilio API发送响应时,我面临415不支持的媒体类型问题 .

我正在使用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));

我为twilio配置了callBackUrl,以便在我的消息状态发生变化时将响应发送到我的系统 .

下面是处理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媒体不支持错误 . 我无法找到确切的rool原因 . 如果有任何问题,请指导我

根据我的理解开发https://www.twilio.com/docs/api/twiml/sms/your_response## Headers ##

这是典型的Twilio入站看起来如何

请求
网址
/ REST /消息/回调/入站/ Twilio?
参数
MESSAGESTATUS发送
APIVERSION 2010-04-01
SMSSID
SMSSTATUS已发送
致91123456789
来自SENDER
MESSAGESID
ACCOUNTSID

1 回答

相关问题