Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WinHTTP problems

8 views
Skip to first unread message

Rob

unread,
Jan 22, 2019, 8:28:46 AM1/22/19
to
I have a *large* legacy program written in VB6, Very successfull,
works fine on all flavours of Windows up to and including 10

Now I need to communicate with a third party using TML Basic Auth and
JSON.

SO far I have created some short code to test the communications:

Dim HttpReq As New WinHttp.WinHttpRequest

HttpReq.SetCredentials "<username>", "<password>", 0


HttpReq.Open "PUT", "https://<API URL>", False


HttpReq.setRequestHeader "Content-Type", "application/json"

HttpReq.Send " "

HttpReq.Send "GET https://<API URL>"

Both the Send methods result in:
{
"status": "error",
"code": 401,
"message": "Access denied"
}


The sane credentials do work OK in Postman app.

What am I missing or doing wrong please?


Wolfgang Εnzinger

unread,
Feb 16, 2019, 5:56:45 PM2/16/19
to
Hi Rob,

not sure why you use "PUT" in the .Open method when a "GET" is what you
actually have in mind, and also what

> HttpReq.Send " "

is intended for.

Try like this, this works fine here:

Dim HttpReq As WinHttp.WinHttpRequest
Set HttpReq = New WinHttp.WinHttpRequest
HttpReq.Open "GET", "https://www.abc.com/xyz/index.html"
HttpReq.SetCredentials "<username>, "<password>", 0&
HttpReq.Send "GET /xyz/index.html"
Debug.Print HttpReq.ResponseText

HTH Wolfgang

Wolfgang Εnzinger

unread,
Feb 16, 2019, 6:12:29 PM2/16/19
to
Am Sat, 16 Feb 2019 23:56:56 +0100 schrieb Wolfgang Εnzinger:

> Dim HttpReq As WinHttp.WinHttpRequest
> Set HttpReq = New WinHttp.WinHttpRequest
> HttpReq.Open "GET", "https://www.abc.com/xyz/index.html"
> HttpReq.SetCredentials "<username>, "<password>", 0&
> HttpReq.Send "GET /xyz/index.html"

The parameter ("GET /xyz/index.html") is redundant here,

>> HttpReq.Send

instead would be sufficient.

> Debug.Print HttpReq.ResponseText

HTH Wolfgang

Wolfgang Εnzinger

unread,
Mar 2, 2019, 3:31:09 PM3/2/19
to
Am Sat, 16 Feb 2019 23:56:56 +0100 schrieb Wolfgang Εnzinger:

> Try like this, this works fine here:

Code now archived at
http://rosettacode.org/wiki/HTTPS/Authenticated#Visual_Basic

:-)
0 new messages