0

I'm writing an application to send SMS to my customers and I integrated with Twilio on localhost successfully. But my test environment is restricted machine and can't access to open network. Someone can define domain and when test machine tries to reach it, that address wilb resolved as address of Twilio. Such as she/he can define an address like this

https://external.domain.com:port

But the question is how can I override host address of Twilio in application level?

Here is sms sending code:

        String ACCOUNT_SID = "";
        String AUTH_TOKEN = "";
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

        try {
            toPhoneNumber = "+" + toPhoneNumber;
            Message message = Message
                    .creator(new PhoneNumber(toPhoneNumber), // to
                            new PhoneNumber("+90..."), // from
                            smsTemplate)
                    .create();

            logger.info("message.getSid():" + message.getSid());
            smsSent = true;
        } catch (Throwable t) {
            logger.error("Error on sending SMS to " + toPhoneNumber);
            logger.error("Error is:");
            logger.error(ExceptionUtils.getFullStackTrace(t));
        }
İlkay Gunel
  • 712
  • 2
  • 11
  • 24

1 Answers1

0

Twilio developer evangelist here.

It sounds like you are trying to use a proxy server to access Twilio and you are using the Java library.

To do this you need to create a custom HTTP client which accesses the API through your proxy server. The good news is that there is a full example of how to create a custom HTTP client to use a proxy in the Twilio documentation here. The example there is much better than anything I could reproduce in this answer, so I recommend you follow the documentation.

philnash
  • 70,667
  • 10
  • 60
  • 88