[MID Server Script Include] How to make rest calls using Packages.com.glide.communications.HTTPRequest through a proxy ?

Harsh Sodiwala
Kilo Explorer

I am using the Packages.com.glide.communications.HTTPRequest object to make HTTP calls as follows

 
this.GlideHTTPRequest = Packages.com.glide.communications.HTTPRequest;
var request = new this.GlideHTTPRequest(<URL>);
request.addHeader(<headerKey>, <header>);
request.post(JSON.stringify(<body>));​

Now I want to make the same HTTP calls through a proxy.

How do I set proxy parameters for this HTTPRequest object ?

I've figured out that the HTTPRequest has the following methods which seems useful:

  • upProxy
  • upProxyUsernamePassword
  • setupProxy
  • setupProxyUsernamePassword

But I do not know how to use them and neither am I sure that these methods are the way to go. Can anybody help me out ?

 
2 REPLIES 2

Jace Benson
Mega Sage

If you're on a MID already why not use a technology you are more familiar with?

Ganesh Bhat
ServiceNow Employee
ServiceNow Employee

Hi,

May be its a late reply, but here is how you get proxy info at MID side

 var Instances = Packages.com.service_now.mid.services.Instances;
            var instance = Instances.get().getPrimaryInstance();

            var proxyHost = instance.getProxyHost();
            var proxyPort = instance.getProxyPort();
            var proxyUsername = (instance.getProxyUserName() != null ? instance.getProxyUserName() : "");
            var proxyPassword = instance.getProxyPassword();

 

then use these

request.setupProxy(proxyHost, proxyPort);

//for domains
request.setupNTLM(userName, proxyPassword, proxyHost, domainName);

//otherwise
request.setupProxyUsernamePassword(proxyUsername, proxyPassword);