VBA HTTP GET Request - Colon Cookies

I am trying to send an HTTP GET request to VBA that contains a cookie containing a colon character, for example:

objReq.Open "GET", "http://my.url.com?foo=bar", False objReq.setRequestHeader "Cookie", "abcd=cookie:containing:colons" objReq.Send 

Depending on what type of object I use for objReq , however, the request is handled differently.

The following object type works:

 Dim objReq As MSXML2.ServerXMLHTTP Set objReq = New MSXML2.ServerXMLHTTP 

Unfortunately, I need to use a different type of object (since MSXML2.ServerXMLHTTP cannot display enough HTTP redirect information). From what I read, I need to use Winhttp.WinHttpRequest , MSXML2.ServerXMLHTTP40 or MSXML2.ServerXMLHTTP60 , but using any of these objects, the following error occurs when the colons are included in the cookie value.

enter image description here

I tried replacing the colons with Chr(58) , %3A , and double quoting inside the string is useless. I also tried adding a Content-Type header with different character encodings, but this does not work either.

Does anyone know how I can send a cookie containing colons using Winhttp.WinHttpRequest , MSXML2.ServerXMLHTTP40 or MSXML2.ServerXMLHTTP60 ?



PS: Otherwise, if anyone knows how I can get the final URL of the redirect sequence when using MSXML2.ServerXMLHTTP , this will work too! Winhttp.WinHttpRequest will allow me to write the status code 302, and MSXML2.ServerXMLHTTP40 or MSXML2.ServerXMLHTTP60 will allow me to use GetOption(-1) , but MSXML2.ServerXMLHTTP does not support any of these methods (from what I can say).

+4
source share
1 answer

I tested WinHttpRequest a bit and I came up with the following code:

 Dim objReq As WinHttp.WinHttpRequest Set objReq = New WinHttp.WinHttpRequest objReq.Option(WinHttpRequestOption_EnableRedirects) = True objReq.Open "GET", "http://www.example.com", False objReq.setRequestHeader "Cookie", "abcd=cookie:containing:colons" objReq.send 

I noticed that I got the same error you posted when I forgot to include "http: //" in the url.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1488815/


All Articles