Results 1 to 9 of 9
  1. #1
    Timaxusa is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    10

    WinHTTP GET stopped working

    Hi, I am new here and have spent a lot of time troubleshooting problem that I have. I wroe code that was working and all of the sudden stopped working... It's a HTTP pull from API and works fine if I access via brower: https://api.binance.com/api/v1/time (you can try and works no problem). When I use access then I get Bad request... Here is my code:
    Dim oRequest As WinHttp.WinHttpRequest
    Dim sResult As String




    Set oRequest = New WinHttp.WinHttpRequest
    With oRequest
    .Open "GET", "https://api.binance.com/api/v1/time", False
    .setRequestHeader "Content-Type", "application/json; charset=UTF-8"
    .send "{}"
    .waitForResponse
    sResult = CStr(.responseText)
    End With
    MsgBox sResult

    I get this:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    <TITLE>ERROR: The request could not be satisfied</TITLE>
    </HEAD><BODY>
    <H1>403 ERROR</H1>
    <H2>The request could not be satisfied.</H2>


    <HR noshade size="1px">
    Bad request.


    <BR clear="all">
    <HR noshade size="1px">
    <PRE>
    Generated by cloudfront (CloudFront)
    Request ID: FEKgNZFE-URt3vcr8X4Mffyo9qZ_WYFt84huUM2gVtGvtaVGpF3dng==
    </PRE>
    <ADDRESS>
    </ADDRESS>
    </BODY></HTML>



    Everything was working fine and stopped working with access.... Please help to understand if I need to add any options to HTTPRequest

    Thank you

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    I have approved your post so others may see it and respond.
    As for the 403 error, I found this

    Code:
    The 403 Forbidden error is an HTTP status code which means that accessing the page or
     resource you were trying to reach is absolutely forbidden for some reason. 
    Can you show us the code and output from one of your successful runs?

    If I go to https://api.binance.com/api/v1/time directly in my browser

    I get this response
    {"serverTime":1524342628518}

  3. #3
    Timaxusa is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    10
    Thank you thank you Orange for responce! Yes, output needs to be {"serverTime":1524342628518} or similar numberbut I get this long error... Banging my head against it. Everything worked until few days ago... not sure what could change. Can you try this code and see if you will get the same?

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Here is a sample using your data. I used Debug.print but you could use MsgBox.

    Code:
    ' ----------------------------------------------------------------
    ' Procedure Name: testhttp
    ' Purpose:To test Winhttp to get a response from binance
    '  from Timaxusa @https://www.accessforums.net/showthread.php?t=71717
    ' Procedure Kind: Sub
    ' Procedure Access: Public
    ' Author: Jack
    ' Date: 22-Apr-18
    ' ----------------------------------------------------------------
    Sub testhttp()
        Dim resp As String
        Dim url As String
    10  url = "https://api.binance.com/api/v1/time"
        Dim Req As New WinHttpRequest
    20  Req.Open "GET", url, False       'set up request structure
    30  Req.Send                         'send the request to binance
        
    40  resp = Req.responseText
    50  Debug.Print "Resp is: " & resp
    End Sub
    Result:

    Code:
    Resp is: {"serverTime":1524399541325}

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Both your code and that done by orange requires the Microsoft WinHTTP Services VBA reference.
    Both versions worked for me.
    Is the reference ticked in the VBE?

    If you still have problems after trying orange's code, here's a variation which requires the VBA XML reference library instead:

    Code:
    Sub TestHTTPGet()
    
    'requires Microsoft XML reference
    Dim sResult As String
    Dim strURL As String
    
    Set http = New MSXML2.XMLHTTP60
    strURL = "https://api.binance.com/api/v1/time"
    
    http.Open "GET", strURL, False
    http.Send ""
    'http.waitForResponse 'omit - doesn't work with XML library
    
    sResult = CStr(http.responseText)
    Debug.Print sResult
    
    End Sub
    Result:
    Code:
    {"serverTime":1524404860952}
    BTW - as the result 1524404860952 is the current UNIX time, wouldn't it make more sense to save the output number part as a double so it can be converted to the current date/time
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    Timaxusa is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    10
    Thank you Orange nad Ridders52! MSXML2.XMLHTTP60 works! For some reason WinHttpRequest is not working on any of my computers... but I was using same copy of database. Can it be corrupted library reference? Also, what is the difference between WinHttp and MSXML2? I was always currious. Best of all!

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    I did include a Reference to WinHttpServices ........... WinHttpCom.dll

  8. #8
    Timaxusa is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    10
    Thank you all. Working now. Used XMLHTTP60 and works as a charm!

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Excellent - odd that WinHTTP version didn't work for you - both methods should work
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Please reply to this thread with any new information or opinions.

Similar Threads

  1. LinkMasterField stopped working
    By PeakH in forum Forms
    Replies: 1
    Last Post: 01-25-2017, 03:56 PM
  2. Subforms stopped working
    By Paul H in forum Forms
    Replies: 7
    Last Post: 06-17-2014, 09:50 AM
  3. Access has stopped working
    By mrkaye in forum Access
    Replies: 0
    Last Post: 05-22-2012, 04:09 PM
  4. Access has stopped working
    By phillb in forum Forms
    Replies: 9
    Last Post: 01-10-2012, 12:22 PM
  5. All Buttons Stopped Working and...
    By rhoridge in forum Programming
    Replies: 1
    Last Post: 12-02-2010, 11:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums