Java-соединение Twilio SMS с прокси-аутентификацией
Я настраиваю java-соединение Twilio, используя пример Twilio java-sdk из примеров API. Единственное отличие состоит в том, что мне нужно запустить мое Twilio-соединение через веб-прокси с аутентификацией. Я попытался реализовать решение как это:
Что я пробовал:
package pack;
import org.apache.http.HttpHost;
import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.DefaultProxyRoutePlanner;
import org.apache.http.message.BasicNameValuePair;
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.MessageFactory;
import com.twilio.sdk.resource.instance.Account;
import com.twilio.sdk.resource.instance.Message;
import java.util.ArrayList;
import java.util.List;
public class Example {
// Find your Account Sid and Token at twilio.com/console
public static final String ACCOUNT_SID = "accound sid";
public static final String AUTH_TOKEN = "account token";
public static final String PROXY_ADDRESS = "202.146.192.174";
public static final int PROXY_PORT = 8080;
public static final String PROXY_USER = "user";
public static final String PROXY_PASSWORD = "pass";
public static void main(String[] args) throws TwilioRestException {
HttpHost proxy = new HttpHost(PROXY_ADDRESS, PROXY_PORT, "http");
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(ACCOUNT_SID, AUTH_TOKEN)
);
CloseableHttpClient httpClient = HttpClients.custom()
.setRoutePlanner(routePlanner)
.setDefaultCredentialsProvider(credentialsProvid`enter code here`er)
.build();
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
client.setHttpClient(httpClient);
Account account = client.getAccount();
MessageFactory messageFactory = account.getMessageFactory();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("To", "+15052079071")); // Replace with a valid phone number for your account.
params.add(new BasicNameValuePair("From", "+15052079071")); // Replace with a valid phone number for your account.`enter code here`
params.add(new BasicNameValuePair("Body", "Hi, this is Devaraj, sending you message from Twilio"));
Message sms = messageFactory.create(params);
} }
Но при запуске кода получаю исключение
Exception in thread "main" java.lang.UnsupportedOperationException: text/html;charset=utf-8 not a supported content type
at com.twilio.sdk.TwilioRestResponse.getParser(TwilioRestResponse.java:231)
at com.twilio.sdk.TwilioRestResponse.toMap(TwilioRestResponse.java:244)
at com.twilio.sdk.TwilioRestException.parseResponse(TwilioRestException.java:58)
at com.twilio.sdk.TwilioClient.safeRequest(TwilioClient.java:509)
at com.twilio.sdk.resource.list.MessageList.create(MessageList.java:70)
at pack.Example.main(Example.java:59)