(Solved) – Problem with Excel VBA changing accept-encoding=”application/gzip” to “gzip, deflate”

(solved)-–-problem-with-excel-vba-changing-accept-encoding=”application/gzip”-to-“gzip,-deflate”

I’m trying to use the google translate API via VBA (works in python so far), and I found that the only difference between the python request and the VBA one is on the header “accept-encoding”, the python one uses the “application/gzip” and works, but the VBA one is automatically changed to “gzip,deflate” even if I change it through code. Here is the code:

Function Test_GoogleTranslate()
    Dim strTranslate As String
    Dim objRequest As Object
    Dim strUrl As String
    Dim blnAsync As Boolean
    Dim strResponse As String
    Dim strWeather As String
    Dim payload As String
    Set objRequest = CreateObject("MSXML2.XMLHTTP")
    payload = "target=es&q=something&source=en"
    strTranslate = "https://google-translate1.p.rapidapi.com/language/translate/v2"
    strTranslate = strTranslate & "?" & payload  
    With objRequest
    .Open "POST", strTranslate, True
    .setRequestHeader "host", "google-translate1.p.rapidapi.com"
    .setRequestHeader "x-forwarded-port", "443"
    .setRequestHeader "x-forwarded-proto", "https"
    .setRequestHeader "connection", "keep-alive"


    .setRequestHeader "content-type", "application/x-www-form-urlencoded"
    .setRequestHeader "accept-encoding", "application/gzip"
    .setRequestHeader "x-rapidapi-host", "google-translate1.p.rapidapi.com"
    .setRequestHeader "x-rapidapi-key", "856e8ba78dmsh443766612c5a923p14f661jsn72323e803261"
    .Send
        While objRequest.readyState <> 4
            DoEvents
        Wend
        strResponse = .ResponseText
    End With
    MsgBox (strResponse)
End Function

When I changed the accept-encoding to “gzip, deflate” in python it crashed, so I figured that might be the problem.
Any help is greatly appreciated

Leave a Reply

Your email address will not be published. Required fields are marked *