Use Sock5 Proxy in VBA - vba

I want to route all the web traffic generated by the Excel VBA tool through a Sock5 Proxy.
I have added the proxy address and port number in Internet Settings in Control Pannel.
But when I analyse through Wireshark the packets that we are being exchanged, I see that my machine is communicating ditrectly with the destination.
However, when I analyse the packet that happens when I use chrome or TOR, the exchange looks to be happening through the Sock5 Proxy server.
Follwing is my snippet that I use to make connection :
xmlhttp.setProxy SXH_PROXY_SET_PRECONFIG
xmlhttp.Open "GET", url, False
xmlhttp.setrequestheader "Content-Type", "text/html"
xmlhttp.setrequestheader "User-Agent", " Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
xmlhttp.setrequestheader "Connection", " keep-alive"
xmlhttp.setrequestheader "Cache-Control", "max-age=0"
xmlhttp.setrequestheader "Accept-Language", "en-us,en;q=0.5"
xmlhttp.setrequestheader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
xmlhttp.send
Though I am not sure whether I am using "SetProxy" correctly or not.
Please Help..

Related

Runtime error while sending Rest request via VBA

I send Rest request to HTTP server via VBA script looking like this:
HTTP.Open "PUT", rUrl, True
HTTP.SetRequestHeader "Host", rHost
HTTP.SetRequestHeader "Authorization", "Bearer " + rToken
HTTP.SetRequestHeader "Content-Length", Len(rBody)
HTTP.send rBody
Everything works fine on Windows 10 (64bit), but I get a runtime error on Windows 7 (64bit) at the line HTTP.send rBody:
Do you know what could cause this error?

WinHTTP Request fails (timeout). Why?

So, I'm trying to send a request to a http server from VBA using the WinHttpRequest class.
I've already made a similar code which sends requests to another server, and it worked. This one won't even go through the ".Send". It fails (timeout).
I've checked every RequestHeader at Google Chrome devtools and tried to replicate the web request, but failed (with and without the cookies).
Any ideas?
The code:
Dim WHTTP As New WinHttp.WinHttpRequest
With WHTTP
.Open "GET", "https://contactcenter-prd.prosodie.com/prweb/sso", False
.SetRequestHeader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
.SetRequestHeader "Accept-Encoding", "gzip, deflate, br"
.SetRequestHeader "Accept-Language", "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7"
.SetRequestHeader "Connection", "keep-alive"
'.SetRequestHeader "Cookie", "JSESSIONID=337C72E2DBCC1080C674033FFC51EBFA.contactcenter; Pega-RULES=" & Chr(34) & "{atn}e3ByfVkzNDBlc3NYRlBYdWFRT2dkRFRjekU5LytjNm51MEMwazI4YmJqVDNvaFlUTE1LQUN3T1p6SUVYMEd5dlUxaHRSWEVINFpJTWVhY1YKdCtpRkQwZjJLdz09" & Chr(34) & "; BWROUTEID=s2ac70d938fbd5ee39c5b1b93ac33d7b.1"
.SetRequestHeader "Host", "contactcenter-prd.prosodie.com"
.SetRequestHeader "Upgrade-Insecure-Requests", "1"
'.SetRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36" ' From Chrome
.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" ' Some guy said it would work (it didn't)
'.SetTimeouts 1200000, 1200000, 1200000, 1200000
.Send
End With
EDIT:
The purpose of the macro is to enter the website, get some info, put the info into a worksheet and exit the website.
I'm aware that the URL redirects to another, but (I think) I have to go to the first website to get some cookies.
EDIT 2:
Problem solved.
I had to setup a proxy to use the website.
.SetProxy 2, myProxy did the trick!
The problem was solved by using .SetProxy 2, proxy.

Passing arguments to Gdax API via VBA HTTP Post

I got a problem in vba while trying to interact with GDAX API.
I get this error: {"message":"Requires product_id"}
I cant pass my product_id in the orders "POST" in WinHttp.WinHttpRequest.5.1 Nothing seems to work:
I tried adding ?product_id=BTC-EUR after the URL as Methodoptions(this works for GET Statements)
i tried adding "product_id=BTC-EUR" after the send
I tried using JsonString = "{""size"": ""0.01"",""price"": ""0.100"",""side"": ""buy"",""product_id"": ""BTC-USD""}" this as postdata
Does anyone know, how to pass those arguments?
This is the code im working with, that works well for all other authenticated statements not passing parameters.
TradeApiSite = "https://api-public.sandbox.gdax.com"
SignMsg = NonceUnique & UCase(HTTPMethod) & "/" & Method & MethodOptions
APIsign = Base64Encode(ComputeHash_C("SHA256", SignMsg, Base64Decode(secretkey), "RAW"))
' Instantiate a WinHttpRequest object and open it
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.Open UCase(HTTPMethod), TradeApiSite & "/" & Method & MethodOptions, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.setRequestHeader "CB-ACCESS-KEY", apikey
objHTTP.setRequestHeader "CB-ACCESS-SIGN", APIsign
objHTTP.setRequestHeader "CB-ACCESS-TIMESTAMP", NonceUnique
objHTTP.setRequestHeader "CB-ACCESS-PASSPHRASE", passphrase
objHTTP.Send '(postdata)
Figured it out after look a bit deeper at how danpaquin/gdax-python does authentication over here https://github.com/danpaquin/gdax-python/blob/master/gdax/gdax_auth.py
You want to send the JSON string as the post data like you described
Content-Type header should be set to application/json
The post data needs to appended to the pre-hash (in your case SignMsg)
Step 2 is important because with out it, GDAX doesn't seem to read your post data - so you get Requires product_id error. If you do step 2 without step 3, you will get invalid signature error

VBA WinHTTP request timeout - error connecting

I am trying to get information from a site, to do this I've created the following VBA code. However, the request will always timeout. Have I made some sort of fundamental mistake?
Right now I'm mimicking the request that my browser would send, perhaps that is the source of the problem. I have seen other posts where this is done and seems to work though.
Code:
Sub fill()
Dim w As New WinHttpRequest
w.SetTimeouts 5000, 5000, 5000, 5000
w.Open "POST", "http://www.vti.net.au/calculator"
w.SetRequestHeader "Host", "www.vti.net.au"
w.SetRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"
w.SetRequestHeader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
w.SetRequestHeader "Accept-Language", "en-US,en;q=0.5"
w.SetRequestHeader "Accept-Encoding", "gzip, deflate"
w.SetRequestHeader "Referer", "http://www.vti.net.au/calculator"
w.SetRequestHeader "Cookie", "SESS85bf6b43b33c734cba757f15a25cc79e=7521a51d45d3609955bf90d18f8d0f90; has_js=1; _ga=GA1.3.2146414506.1410196274"
w.SetRequestHeader "Connection", "keep-alive"
w.Send "Length=330&Connectors=4&Splices=4&Cord=1&submit=Calculate"
MsgBox "test"
End Sub
Request info:

default credentials in VBA

I'm tryng to make a HTTP request from VB for Applications ( VBA)
that should have been simple:
URL = "https://www.google.com/"
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xhr.Open "GET", URL, False
xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xhr.Send
MsgBox xhr.responseText
BUT I'm behind a proxy server which require basic auth (base64).
How to set the credentials in VBA ?
(something equivalent to : myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials)
If this is not possible, how to solve the issue with another approach ?
Thanks !
You'd need the setProxyCredentials method. I don't have a proxy to test, but this should do the trick:
URL = "https://www.google.com/"
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xhr.Open "GET", URL, False
xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xhr.setProxy 2, "192.168.0.222:8080"
xhr.setProxyCredentials "your_username" , "password_for_username"
xhr.Send
MsgBox xhr.responseText
Taken from This Question which points out the 2 argument is a version number that you may need to change.