Created
November 8, 2011 19:53
-
-
Save DexterHaslem/1348944 to your computer and use it in GitHub Desktop.
debug print streaming web request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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