Skip to content

Instantly share code, notes, and snippets.

@DexterHaslem
Created November 8, 2011 19:53
Show Gist options
  • Save DexterHaslem/1348944 to your computer and use it in GitHub Desktop.
Save DexterHaslem/1348944 to your computer and use it in GitHub Desktop.
debug print streaming web request
let printStreamingWebReq (url : string, postContent : string) =
let req = WebRequest.Create url :?> HttpWebRequest
req.Method <- "POST"
req.Proxy <- null
let postDataEncoded = ASCIIEncoding.ASCII.GetBytes(postContent)
let len : int64 = int64 postDataEncoded.Length
req.ContentLength <- len
let reqStream = req.GetRequestStream()
reqStream.Write(postDataEncoded, 0, postDataEncoded.Length)
use response = req.GetResponse()
use responseStream = response.GetResponseStream()
use reader = new StreamReader(responseStream)
while true do
let buff = [| '0' |]
let bytesRead = reader.Read(buff, 0, 1)
if bytesRead > 0 then
printf "%c" buff.[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment