.NET Framework Bookmark and Share   
 index > Network Class Library (System.Net) > HttpWebRequest Sending Multiple Packets
 

HttpWebRequest Sending Multiple Packets

I have a .Net class that I amwriting to send and receive some information thru SSL with a 3rd party vendor.
I am using the HTTPWebRequest / HTTPWebResponse objects to accomplish this.

One thing is that I am being told by the vendor thatI am to send a three seperate packets "on the same connection".
In other words :
1) create the request
2) send packet A
3) read the response
4) send packed B
5) read the response
6) send packet C
7) read the response
7) close


This doesn't seem to make sense to me since the request is created and then whatever headers are created.This includes a Content-Length header that changes with each packet sent.

As long as I send just one packet, the code works perfectly. I have not been able to figure out how to send a second packet without createing a new HTTPWebRequest.

Here's the code that works with the 1 packet.
I need to know how to alter this code to do the 7 steps mentioned above. It may not be possible but, since they (my vendor) havesuggested that this is howthey 'need' the data,

oHTTPSRequest =

DirectCast(HttpWebRequest.Create(<MyURLHere>), HttpWebRequest)

sPacket = Me.CreateRequestPacket(voRequest)

Debug.Print(sPacket)

'ViewRawPacket(sPacket)

'Create the packet bytes from the ASCII encoder

btRequest = oEncoding.GetBytes(sPacket)

'Create the HTTPS Request header

GenerateRequestHeader(oHTTPSRequest, btRequest.Length)

'Get the stream from the request to write to

oRequestStream = oHTTPSRequest.GetRequestStream()

oRequestStream.Write(btRequest, 0, btRequest.Length)

oRequestStream.Close()

'Wait for the response from the request

oHTTPSResponse =

DirectCast(oHTTPSRequest.GetResponse(), HttpWebResponse)

'Create a stream reader from the response object and encode it as ASCII

oResponseStream =

New StreamReader(oHTTPSResponse.GetResponseStream(), System.Text.Encoding.ASCII)

'Read it into a string

sResponseText = oResponseStream.ReadToEnd

'ViewRawPacket(sResponseText)

Debug.Print(sResponseText)



  •  
Steve Frase
Unfortunately, HttpWebRequest does not allow this type of programming pattern. HttpWebRequest restricts you to send your data first, and then read the response for each usage of a particular instance of HttpWebRequest.

Seems to me like you are tunnelling your own protocol over HTTP. If that is the case, you can get around this by using Socket class directly. First, send a valid HTTP request over the socket to get the connection started with the server, and then you can write your packet, and read the response from the server.
feroze
--
My blog
  • Marked As Answer bySteve Frase Tuesday, September 01, 2009 5:19 PM
  •  
Feroze Daud
Unfortunately, HttpWebRequest does not allow this type of programming pattern. HttpWebRequest restricts you to send your data first, and then read the response for each usage of a particular instance of HttpWebRequest.

Seems to me like you are tunnelling your own protocol over HTTP. If that is the case, you can get around this by using Socket class directly. First, send a valid HTTP request over the socket to get the connection started with the server, and then you can write your packet, and read the response from the server.
feroze
--
My blog
  • Marked As Answer bySteve Frase Tuesday, September 01, 2009 5:19 PM
  •  
Feroze Daud
You confirmed my suspicion that it was not able to be used this way.
The idea of switching to a socket is a good idea if it turns out that it has to be sent on the very same connection.
I appreciate your input.
Steve Frase

You can use google to search for other answers

Custom Search

More Threads

• Webexception:- "The request was aborted: The request was canceled."
• P2P Collabortation with .net and windows xp
• NetworkAvailabilitychangedEvent
• .NET c# Sockets server
• Problem Reading cookie in windows form
• Unable to send email using Dynamic IP
• Server not responding to new clients .. connecting to only one client
• Checking if remote ip address is connected to the server
• problem downloading binary file
• Mail sending fail ...