• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

WinHttp WinHttpRequest works only on windows 10

YasserKhalil

Well-Known Member
I have the following working code on windows 10

Code:
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://eileenslounge.com/viewtopic.php?f=30&t=40673
 
Maybe some missing header(s) so check manually what the webbrowser uses …​
As a reminder when WinHttp can't XmlHttp can't​
but when XmlHttp can't WinHttp may succeed as XmlHttp is obsolete, so to avoid.​
 
The same headers and the same code works for windows 10 but not for windows 7
I tried to enable TLS 1.2 but the same problem persists.
 
To be clear enough I should write « so check manually what the webbrowser uses under Seven » …​
 
If it works manually under whatever the webbrowser then again just check the headers used …​
If it works as it is under another computer under the same Windows version then​
that's specific to the Windows setup, maybe a recent Windows update broke something.​
Or that may come from some anti-virus setting …​
 
Back
Top