我试图通过twilio发送短信。我可以发送消息的号码,但问题是我的整个应用程序开始发送xml作为响应。它影响了我的整个应用程序。如何转换,使我可以得到json作为响应。我是新的。请有人帮助我。
sms发送成功,但我的整个应用程序开始得到响应作为xml.
这是我的控制器:
@RequestMapping(value = "/sendmessage", method = RequestMethod.POST)
public ResponseEntity<String> sendmessage(@RequestBody UserDto userDto) {
return userRegisterService.sendmessage(userDto.getMobileNumber(), userDto.getSmsMessage());
}
这是我的服务类:
@PostConstruct
private void setup() {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
}
public ResponseEntity<String> sendmessage(String MobileNumber, String SmsMessage) {
Message.creator(new PhoneNumber(MobileNumber), new PhoneNumber(OUTGOINGSMSNumber), SmsMessage).create();
return new ResponseEntity<String>("Message sent successfully", HttpStatus.OK);
}
}
我还没有明确地写任何地方转换为xml。只是添加twilio依赖项就可以将整个应用程序转换为xml。
1条答案
按热度按时间0lvr5msh1#
根据Twilio文件:
默认情况下,Twilio的REST API返回XML,根元素为。例如,以下是SMS消息的默认XML表示:
进一步阅读:https://www.twilio.com/docs/usage/twilios-response
使用API,表面上是Twilio Jar覆盖Spring配置,如果你想继续使用它,通过添加
produces
到@RequestMapping
来注解你的Spring控制器