Jump to content

_WinHttpReadData to file

Recommended Posts

Hi I have had major break through with my project this weekend and have been able to successfully communicating with the server im working with. However My latest request I got the HTML document as a response from the server when I try to read like so:

Func _GetResopnse($string)
  $sChunk = ""
  $sData = ""
  ConsoleWrite("Response " & $string & @CRLF)
   If _WinHttpQueryDataAvailable($hRequest) Then
       ; Read
       While 1
          $sChunk = _WinHttpReadData($hRequest)
          If @error Then ExitLoop
          $sData &= $sChunk
          ConsoleWrite("   " & $sData & @CRLF) ; print to console
          ; <== Check login status
          If StringInStr($sData, '"success":true') Then
             ;MsgBox(0, "", "Login success")
            ;MsgBox(0, "", "Login failed")
       MsgBox(48, "Error", "Site is experiencing problems.")
    ConsoleWrite("/Response" & @CRLF)

This works very well in the consolelog however I want to write all this data into a textfile. I thought that would be simple enough doing something like this 

Local Const $htmlFilePath = @ScriptDir & "\System\htmldoc.txt"
Local $hFileOpen = FileOpen($htmlFilePath, $FO_APPEND)
     FileWrite($hFileOpen, $sData)


But with this I only get a blank txt document. any pointers to what I could do ?



Share this post

Link to post
Share on other sites
Posted (edited)
21 hours ago, Acce said:

any pointers to what I could do ?

Have you looked at InetGet()?  It will get the result of an HTTP GET request and put the result in a file, all in one function call.  :doh: Or, you can look at InetRead(), which will do the same thing as InetGet() except the result is a binary string instead of a saving the result in a file.

Edited by TheXman
Fixed InetRead() hyperlink

Share this post

Link to post
Share on other sites

TheXman Thanks for the info , will do some testing now thanks for pointing me in the right direction 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...