Search code examples
phpexcelutf-8winhttpvba

download xml file from url using winhttp in excel - CHARSET=UTF-8


I am trying to automate downloading of xml file from a url. Even after multiple attempts I couldn't think of possible solution to this and wonder if anyone could help me by just looking at the output and response header, url being sensitive.

Using the excel I am doing a http request via winhttp to the url and in the response.body its giving the ouput which I can't figure out how to read and get the data out of it.

Request header

   url = "https://***sensitive***.com/psc/FS91PRD/EMPLOYEE/ERP/q/?ICQryName=W_GL_INTL_JNLS&ICDummy=1186278907"

    With http
        .Open "POST", url, False
        .setRequestHeader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
        .setRequestHeader "Referer", "https://***sensitive***_GL_INTL_JNLS&ICDummy=1186278907"
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .setRequestHeader "Accept-Encoding", "gzip, deflate"
        .setRequestHeader "Host", "***sensitive****"
        '.setRequestHeader "Content-Length", "360"
        .setRequestHeader "Connection", "keep-alive"
        .setRequestHeader "cache-Control", "no-cache"
        .setRequestHeader "Cookie", cookie2
        .send postData
        .waitForResponse
    End With

End If


Debug.Print http.getAllResponseHeaders

Response header

Date: Sun, 24 May 2015 14:03:13 GMT
Content-Length: 10673
Content-Type: text/html; CHARSET=UTF-8
Content-Encoding: gzip
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Set-Cookie: PS_TOKENEXPIRE=24_May_2015_14:03:13_GMT; 
IgnorePortalRegisteredURL: 1
PortalRegisteredURL: https://***sensitive***.com/
UsesPortalRelativeURL: true
X-Powered-By: Servlet/2.5 JSP/2.1

Output String

enter image description here


Solution

  • See the Content-Encoding: gzip? You need to decompress the body using gzip, or use a client library that will do it for you.

    Just as a side note, though, if the server sent you a gzipped response when you didn't send Accept-Encoding: gzip, there's something wrong with it.