WinHttp WinHttpRequest works only on windows 10

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

WinHttp WinHttpRequest works only on windows 10

Post by YasserKhalil »

I have the following working code on windows 10

Code: Select all

Sub Test()
    Const sURL As String = "https://oppaapi.emis.gov.eg/api/pl/IsDocumentIdValid"
    Dim a, ws As Worksheet, sh As Worksheet, http As Object, sNationalID As String, sResp As String
    Set ws = shINF: Set sh = shSN
    Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
    sNationalID = sh.Range("B1").Value
    With http
        .Open "GET", sURL & "?DocumentId=" & sNationalID & "&IdType=1", False
        On Error GoTo ErrBearer
        .setRequestHeader "Authorization", Replace(ws.Range("A5").Value, "Authorization: ", Empty)
        .setRequestHeader "Referer", "https://student.emis.gov.eg/"
        .setRequestHeader "schoolCode", ws.Range("D2").Value
        On Error GoTo ErrPoint
        .send
        sResp = .responseText
    End With
ErrPoint:
    MsgBox "Operation Aborted", vbExclamation: Exit Sub
ErrBearer:
    MsgBox "Get New Authorization", vbExclamation: Exit Sub
End Sub
In the past, such code was working on Windows 7 but now I don't know why it doesn't work on 7. I tried to use xmlhttp but the same problem.

Posted here too https://chandoo.org/forum/threads/winht ... -10.56240/

User avatar
SpeakEasy
4StarLounger
Posts: 563
Joined: 27 Jun 2021, 10:46

Re: WinHttp WinHttpRequest works only on windows 10

Post by SpeakEasy »

>https

Silly question I know, but are you sure port 443 isn't blocked by a firewall on the W7 machine?

Also, can you clarify "doesn't work on 7"? In what way does it not work?

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Re: WinHttp WinHttpRequest works only on windows 10

Post by YasserKhalil »

How can I know if port 443 is not blocked?
The error occurs (as the code goes to ErrPoint: MsgBox "Operation Aborted", vbExclamation: Exit Sub)

User avatar
SpeakEasy
4StarLounger
Posts: 563
Joined: 27 Jun 2021, 10:46

Re: WinHttp WinHttpRequest works only on windows 10

Post by SpeakEasy »

So at that point what are err.description and err.number?

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Re: WinHttp WinHttpRequest works only on windows 10

Post by YasserKhalil »

I got this error
-2147012866
The connection with the server was terminated abnormally

User avatar
SpeakEasy
4StarLounger
Posts: 563
Joined: 27 Jun 2021, 10:46

Re: WinHttp WinHttpRequest works only on windows 10

Post by SpeakEasy »

Beginning to sound like it may be a TLS issue. I suggest Googling something like "Enable TLS 1.2 on Windows 7"