The other day, I was trying to use the ServerXMLHTTP object. For information, this object was created to allow you to establish server-to-server HTTP connections.
The code I firstly wrote looked like the following:
Dim oXMLHTTP Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP") oXMLHTTP.open "POST", sURL, false oXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" oXMLHTTP.send sParams Response.Write oXMLHTTP.responseText
with sURL
the URL to call and sParams
the parameters to send with the URL.
The problem was that oXMLHTTP.responseText
didn’t return anything. Or to be exact, it returned an empty string, which was obviously not the expected response… 🙁
After some investigation, it appeared that the problem was because the server was seating behind a proxy. All this is good and well, but the question now is how to tell the application to use the proxy?
First of all, the ServerXMLHTTP object has a setProxy
method:
http://msdn.microsoft.com/en-us/library/ms760236(v=VS.85).aspx
So I tried to add the following line to the previous code:
oXMLHTTP.setProxy 2, "myProxyServer:80", ""
Unfortunately, this didn’t fix the problem. It looks like this line is simply ignored. If somebody knows why, please tell me! 😉
So the solution I finally adopted was to configure the proxy through the proxycfg tool.
There are two ways of using this tool:
- Import the proxy settings from the current user’s Microsoft Internet Explorer manual settings using the command
proxycfg.exe -u
- Configure the proxy settings manually using the command
proxycfg -p myProxyServer:80
This last solution works for me and I hope it will help a few people. 🙂
PS: I found the following page when writing this article: http://support.microsoft.com/kb/289481/. It would have been so good to find it during my investigation but anyway.
#1 by RBorchert on 15 Dec 2011 - 20:57
I had the same problem
Turns out, instead of
oXMLHTTP.setProxy 2, “myProxyServer:80”, “”
You need to have
oXMLHTTP.setProxy 2, “http=myProxyServer:80”, “”
You can specify one proxy server for each protocol, and you have to say which protocol each one is for
#2 by smoreau on 15 Dec 2011 - 23:51
Brilliant! Thank you for your input. 🙂
#3 by Hemal Nanavati on 06 Oct 2014 - 12:18
Just found out the reason why simply using setProxy method to use proxy settings didn’t work as this method only works with MSXML version 3.0 and 6.0.
Need to use the latest version of ServerXMLHTTP object:
Set gobjHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
#4 by XLE_22 on 02 Dec 2014 - 14:32
Wouahou… great, thanks for this tip !
Everything works like a charm without ‘http=’ in front of the proxy when the version is specified.