Larry Brister
asked on
Multiple httpwebrequests into response stream loop? Difficult
I AM doing an httpwebrequest POST to a url
What I need to do is multiple posts and do a single response stream if possible.
In my code below the response is kept "open" with the While "Canread" method.
The postdata goes in like this...but I can only send 7 at a time in the same POST
I NEED to send 7 at a time with a 3 second pause between posts"
<command><id>123</id></com mand>
<command><id>124</id></com mand>
<command><id>125</id></com mand>
<command><id>126</id></com mand>
And again...after the posts above run, I need to montor all the events
etc...
End While
What I need to do is multiple posts and do a single response stream if possible.
In my code below the response is kept "open" with the While "Canread" method.
The postdata goes in like this...but I can only send 7 at a time in the same POST
I NEED to send 7 at a time with a 3 second pause between posts"
<command><id>123</id></com
<command><id>124</id></com
<command><id>125</id></com
<command><id>126</id></com
And again...after the posts above run, I need to montor all the events
Dim sendWebRequest As HttpWebRequest = CType(WebRequest.Create(stUrl), HttpWebRequest)
sendWebRequest.SendChunked = True
sendWebRequest.Method = "POST"
sendWebRequest.ContentType = "text/plain"
sendWebRequest.KeepAlive = True
sendWebRequest.UserAgent = "CometTest"
'PUT A LOOP AROUNT THE getbytes???
Dim encodedData As New ASCIIEncoding()
Dim byteArray As Byte() = encodedData.GetBytes(postData)
sendWebRequest.ContentLength = byteArray.Length
Dim newStream As Stream = sendWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)
newStream.Close()
Using myHttpWebResponse As HttpWebResponse = CType(sendWebRequest.GetResponse(), HttpWebResponse)
Using streamResponse As Stream = myHttpWebResponse.GetResponseStream()
'Next Line tricks into staying in Response Stream Loop
While streamResponse.CanRead
etc...
End While
ASKER
CodeCruiser,
How would that loop look?
What would it be around?
NOt sure where the byteArray2, 3 etc is coming form.
How would that loop look?
What would it be around?
NOt sure where the byteArray2, 3 etc is coming form.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
Great example and I can get through this.
Great example and I can get through this.
Dim newStream As Stream = sendWebRequest.GetRequestS
newStream.Write(byteArray,
Thread.Sleep(4000)
newStream.Write(byteArray2
Thread.Sleep(4000)
newStream.Write(byteArray3
Thread.Sleep(4000)
...
newStream.Close()
You may want to utilize a loop.