Solved

HttpWebResponse

Posted on 2013-07-01
4
344 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
[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
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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

622 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