第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Twilio SMS api 不支持返回內(nèi)容類(lèi)型

Twilio SMS api 不支持返回內(nèi)容類(lèi)型

蕪湖不蕪 2023-05-17 15:58:49
目前我正在處理一個(gè)需要將 SMS 檢索功能添加到系統(tǒng)中的項(xiàng)目。我已經(jīng)使用 spingboot 來(lái)構(gòu)建應(yīng)用程序。所有的實(shí)現(xiàn)都完成了,我已經(jīng)按照 twillio 上的所有必要配置從客戶(hù)端檢索短信。當(dāng)我向 Twilio api 發(fā)送短信時(shí),它會(huì)Unsupported Media Type在調(diào)試器中說(shuō)明。我還向 api 發(fā)送了所需的內(nèi)容類(lèi)型。當(dāng)我向 twilio 提供的號(hào)碼發(fā)送短信時(shí)會(huì)發(fā)生這種情況。但是郵遞員調(diào)用應(yīng)用程序工作正常。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;@RestControllerpublic 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());    }}
查看完整描述

2 回答

?
智慧大石

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊

恕我直言,api 調(diào)用是最佳選擇。RestTemplate請(qǐng)使用如下所示使用已發(fā)布的 API 進(jìn)行實(shí)施。


public void sendOTP() {

    RestTemplate restTemplate = new RestTemplate();


    String message = "Your PIN for account verification is 123456";

    String user = "******405e4c****19d0******";

    String password = "******";

    String smsurl = "https://api.twilio.com/2010-04-01/Accounts/"+user+"/Messages.json";


    HttpHeaders headers = new HttpHeaders();

    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);


    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();

    map.add("From", "+1334384****");

    map.add("To", "+999999999");

    map.add("Body", message);


    HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(map, headers);


    try {

        restTemplate.getInterceptors().add(new BasicAuthenticationInterceptor(user, password));

        Object response = restTemplate.postForObject(smsurl, httpEntity, Object.class);

        LOG.info("Sms Response: {}", gson.toJson(response));

    } catch(Exception e) {

        LOG.error(e.getMessage());

    }

}


查看完整回答
反對(duì) 回復(fù) 2023-05-17
?
青春有我

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超8個(gè)贊

您認(rèn)為客戶(hù)端沒(méi)有指定內(nèi)容類(lèi)型。請(qǐng)補(bǔ)充content-type: application/xml。


如果你有 spring boot,你可以通過(guò)添加以下依賴(lài)項(xiàng)來(lái)修復(fù)它:


<dependency>

     <groupId>com.fasterxml.jackson.dataformat</groupId>

     <artifactId>jackson-dataformat-xml</artifactId>

     <version>2.9.8</version>

</dependency>


查看完整回答
反對(duì) 回復(fù) 2023-05-17
  • 2 回答
  • 0 關(guān)注
  • 155 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)