Solved

Multiple httpwebrequests into response stream loop?  Difficult

Posted on 2013-06-25
4
366 Views
Last Modified: 2013-06-25
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></command>
<command><id>124</id></command>
<command><id>125</id></command>
<command><id>126</id></command>


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

Open in new window


              etc...
        End While
0
Comment
Question by:lrbrister
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Modify following section

Dim newStream As Stream = sendWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)
Thread.Sleep(4000)
newStream.Write(byteArray2, 0, byteArray2.Length)
Thread.Sleep(4000)
newStream.Write(byteArray3, 0, byteArray3.Length)
Thread.Sleep(4000)
...
newStream.Close()



You may want to utilize a loop.
0
 

Author Comment

by:lrbrister
Comment Utility
CodeCruiser,
  How would that loop look?

What would it be around?

NOt sure where the byteArray2, 3 etc is coming form.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
bytearray2, 3 etc are created by breaking your original xml to segments of 7 phones and then converting to byte array. Loop may look like

For i as integer = 0 to PhoneCount/7 - 1
      XmlString = GetXmlString(OriginalXML, StartIndex)
      ByteArray = GetByteArray(XmlString)
      newStream.Write(byteArray, 0, byteArray.Length)
      Thread.Sleep(4000)
Next


Note: Above is  just an algorithm not actual code.
0
 

Author Closing Comment

by:lrbrister
Comment Utility
Thanks.
Great example and I can get through this.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now