Solved

HttpWebResponse

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hangfire / asp.net sample 3 31
How to change a specific bit from a file 2 21
Expando 4 36
Red error squiggly on vb.net 7 14
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…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

12 Experts available now in Live!

Get 1:1 Help Now