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 ----
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 ----