Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Multiple httpwebrequests into response stream loop?  Difficult

Posted on 2013-06-25
4
371 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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…

828 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