Solved

HttpWebResponse

Posted on 2013-07-01
4
339 Views
Last Modified: 2013-07-03
I have a multi thread HttpWebRequest and CanRead Open response stream working.

I am asked if this can be placed in a single response stream

Since I have to make multiple posts...no way out of it...

Is there ANY way I can channel all the different WebRequest responses into a single response stream?
0
Comment
Question by:lrbrister
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 39293769
using System;
using System.Net;
using System.Text;
using System.IO;


    public class Test
    {
        // Specify the URL to receive the request. 
        public static void Main (string[] args)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);

            // Set some reasonable limits on resources used by this request
            request.MaximumAutomaticRedirections = 4;
            request.MaximumResponseHeadersLength = 4;
            // Set credentials to use for this request.
            request.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse ();

            Console.WriteLine ("Content length is {0}", response.ContentLength);
            Console.WriteLine ("Content type is {0}", response.ContentType);

            // Get the stream associated with the response.
            Stream receiveStream = response.GetResponseStream ();

            // Pipes the stream to a higher level stream reader with the required encoding format. 
            StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);

            //Instead of console have one stream and keep on appending. By this way you could have one response which contains more response stream.
            Console.WriteLine ("Response stream received.");
            Console.WriteLine (readStream.ReadToEnd ());
            response.Close ();
            readStream.Close ();
        }
    }

Open in new window



Please do refer below links for more information:

http://forums.asp.net/t/1779147.aspx/1
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx
http://www.dotnetperls.com/streamreader
0
 

Author Comment

by:lrbrister
ID: 39293794
EaswaranP,
  I want to make sure I've stated this correctly

I need to make a series of posts in HTTP Web Request.

How do I do that (using your example) when I'm doing this in each thread right now...
I'm removing a bit of that header information...not needed)

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
sendWebRequest.ReadWriteTimeout = System.Threading.Timeout.Infinite


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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39297155
I would say you can't do that as the response stream comes from response and response is to your request which is isolated and running in its own thread.
0
 

Author Closing Comment

by:lrbrister
ID: 39297176
After quite a bit of research I agree.

Just had to validate with my manager
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to join on ID, with prefix? 15 60
What can cause the styling on a .NET site to not be found? 17 27
vb.net help 4 31
vb.net class 3 17
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:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

832 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