【发布时间】:2019-08-05 06:50:22
【问题描述】:
目前我正在处理一个需要向系统添加 SMS 检索功能的项目。我已经使用 spingboot 来构建应用程序。所有的实现都完成了,我已经按照 twillio 上的所有必要配置从客户端检索短信。当我向 Twilio api 发送短信时,它会在调试器中声明 Unsupported Media Type。我还将所需的内容类型发送到 api。 当我向 twilio 提供的号码发送短信时会发生这种情况。但是邮递员调用应用程序工作正常。
package com.crustykrabs.application.service;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import static spark.Spark.*;
import com.twilio.twiml.MessagingResponse;
import com.twilio.twiml.messaging.Body;
import com.twilio.twiml.messaging.Message;
@RestController
public class TextMessageController {
@PostMapping(path = "/messages/textmessages/receive", consumes = "application/xml", produces = "application/xml")
public @ResponseBody ResponseEntity<String> receive() {
Body body = new Body
.Builder("The Robots are coming! Head for the hills!")
.build();
Message sms = new Message
.Builder()
.body(body)
.build();
MessagingResponse twiml = new MessagingResponse
.Builder()
.message(sms)
.build();
return ResponseEntity.ok().contentType(MediaType.APPLICATION_XML).body(twiml.toXml());
}
}
【问题讨论】:
-
看起来你发送给你自己的控制器(而不是 Twilio)的不是
application.xml,而只是一个常规的表单提交。您要向控制器发送什么请求? IN show 只需从映射中删除consumes。您正在执行常规表单提交而不是发送 xml。
标签: java spring spring-boot twilio twilio-api