?
Solved

Multiple httpwebrequests into response stream loop?  Difficult

Posted on 2013-06-25
4
Medium Priority
?
375 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
[X]
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
  • 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 2000 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

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

719 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