Solved

Multiple httpwebrequests into response stream loop?  Difficult

Posted on 2013-06-25
4
369 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
ID: 39274638
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
ID: 39274676
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
ID: 39274728
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
ID: 39274949
Thanks.
Great example and I can get through this.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can my static class become undefined?? 8 47
Disable extension 8 37
Reading the web config for a running service on Windows 10 16 40
Regular expression help 2 24
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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