WinHttp.WinHttpRequest.5.1 Request And The Mysterious Case Of Missing Session Variables

MatthewNYC

New Member
Joined
Feb 19, 2017
Messages
18
Hi,

I have the following WinHttp request code that opens an ASP.net page (using .NET CLR Version v4.0.30319) on my website which returns data in the JSON format.

The problem I'm experiencing is when WinHttp opens the URL, the Session and Application variables in the ASP.net webpage completely don't work. This causes the WinHttp request to hit errors in the webpage.

If I open the exact same URL using a web browser such as IE or Chrome, the page loads perfectly and returns the correct JSON data.

It appears the WinHttp request coming from Excel VBA is not recognized by IIS as being a valid browser worthy of access to the Session/Application objects.

How to solve this?

---- begin code sample ----

Dim strRequestType As String
Dim objHTTP As Object

If strPostParameters <> vbNullString Then
strRequestType = "POST"
Else
strRequestType = "GET"
End If

Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")


With objHTTP


.Open strRequestType, strURL, False


.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
.SetRequestHeader "Content-type", "application/x-www-form-urlencoded"

If strPostParameters <> vbNullString Then
.Send (strPostParameters)
Else
.Send
End If

m_strResponseText = .ResponseText
m_strResponseStatus = .Status

---- end code sample ----
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top