Solved

HttpWebRequest

Posted on 2013-07-01
8
467 Views
Last Modified: 2013-07-01
I feel stupid for asking...

Is there any way to do a "phased POST" on an HttpWebRequest?

In my code below
Without opening another connection
can the Dim newStream As Stream = sendWebRequest.GetRequestStream() be done in pieces?

Here's my code that works.
Dim sendWebRequest As HttpWebRequest = CType(WebRequest.Create(stUrl), HttpWebRequest)

'Following items 
 sendWebRequest.SendChunked = True
sendWebRequest.Method = "POST"
sendWebRequest.ContentType = "text/plain"
sendWebRequest.KeepAlive = True
sendWebRequest.UserAgent = "CometTest"
sendWebRequest.ServicePoint.ConnectionLimit = 20
sendWebRequest.Timeout = 43200


Dim encodedData As New ASCIIEncoding()
Dim byteArray As Byte() = encodedData.GetBytes(sendRow)

sendWebRequest.ContentLength = byteArray.Length

Dim newStream As Stream = sendWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)
newStream.Close()

Open in new window

0
Comment
Question by:lrbrister
  • 4
  • 3
8 Comments
 
LVL 11

Expert Comment

by:lenordiste
Comment Utility
what is supposed to be a "phased POST" for you? if you are looking for the asynchronous way of handling this, here is a start:
http://msdn.microsoft.com/en-us/library/system.net.webrequest.getrequeststreamasync.aspx

if not, what are you trying to accomplish :) ?
0
 

Author Comment

by:lrbrister
Comment Utility
I have a POST of XML I'm sending to the HttpWebRequest
It looks like
<command><id>1</id></command>
<command><id>2</id></command>
<command><id>3</id></command>
<command><id>4</id></command>
<command><id>5</id></command>
<command><id>6</id></command>
<command><id>7</id></command>
<command><id>8</id></command>

So I want to "Open a Post???"
send first 4
pause 1000 milli seconds with a sleep
send the other 4
Complete the post.

I THINK this is a dumb question...
Just not experienced enough with the POST part to know.
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
After you've done the first post would not the server then think that you've finished and not know what to do with the remaining posts?
0
 

Author Comment

by:lrbrister
Comment Utility
ve3ofa

That's what I keep trying to say.

As I mentioned above..
This is not my area of expertise.

So that's why I'm asking if there is a "threaded" post
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Expert Comment

by:lenordiste
Comment Utility
the only thing that comes to mind is the http keep-alive which is turned on by default and allows http requests to reuse TCP connections. Codewise there's no really such thing as to "open a post". That being said, why don't you use more than one xml command in a single post?
0
 

Author Comment

by:lrbrister
Comment Utility
lenordiste

Not sure that would work

In my list above I'm currently posting 4 at a time in separate threaded posts.

On the VENDOR end...
They only allow (x) numbers in the "waiting" status on the post at a time.

In any event...
How could I send more that one xml command at a time?
0
 
LVL 11

Accepted Solution

by:
lenordiste earned 500 total points
Comment Utility
your scenario looks fine by the way:
send first 4
wait a bit
send next 4
etc.

there is some overhead for each POST of course, but you cannot reduce that overhead in any meaningful way. If you are looking for performance improvements you may consider using json or another lighter data format than XML.
0
 

Author Closing Comment

by:lrbrister
Comment Utility
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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:…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

10 Experts available now in Live!

Get 1:1 Help Now