Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9019683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:50:27+00:00 2026-06-16T04:50:27+00:00

I made a Function for a program, which does work when the Request Type

  • 0

I made a Function for a program, which does work when the Request Type is GET, if it is POST, it always produces a Timeout Exception(and the timeout of 50s wasnt reached) on the Line HttpWebResponse response = (HttpWebResponse)request.GetResponse();

I tried many things, but I doesnt found out why, may someone here know it.

Edit: Got it to work, if someone is interested: https://gist.github.com/4347248

Any help will be greatly appreciated.

My Code is:

public ResRequest request(string URL, RequestType typ, CookieCollection cookies, string postdata ="", int timeout= 50000)
    {
        byte[] data;
        Stream req;
        Stream resp;

        HttpWebRequest request = WebRequest.Create(URL) as HttpWebRequest;
        request.Timeout = timeout;
        request.ContinueTimeout = timeout;
        request.ReadWriteTimeout = timeout;
        request.Proxy = new WebProxy("127.0.0.1", 8118);
        request.Headers.Add(HttpRequestHeader.AcceptLanguage, "de");
        request.Headers.Add("UA-CPU", "x86");


        request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
        request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618) ";
        request.CookieContainer = new CookieContainer();
        request.CookieContainer.Add(cookies);
        if (typ == RequestType.POST)
        {
            data = System.Text.Encoding.Default.GetBytes(postdata);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;
            req = request.GetRequestStream();//after a few tries this produced a Timeout error
            req.Write(data, 0, data.Length);
            req.Close();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();//This line produces a Timeout Exception
            resp = response.GetResponseStream();

            if ((response.ContentEncoding.ToLower().Contains("gzip"))) 
            {
                resp = new System.IO.Compression.GZipStream(resp, System.IO.Compression.CompressionMode.Decompress);
            } else if ((response.ContentEncoding.ToLower().Contains("deflate"))) {
                resp = new System.IO.Compression.DeflateStream(resp, System.IO.Compression.CompressionMode.Decompress);
            }

            return new ResRequest() { result = new System.IO.StreamReader(resp, System.Text.Encoding.UTF8).ReadToEnd(), cookies = response.Cookies, cstring = cookiestring(response.Cookies) };

        }
        else
        {
            request.Method = "GET";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            resp = response.GetResponseStream();

            if ((response.ContentEncoding.ToLower().Contains("gzip")))
            {
                resp = new System.IO.Compression.GZipStream(resp, System.IO.Compression.CompressionMode.Decompress);
            }
            else if ((response.ContentEncoding.ToLower().Contains("deflate")))
            {
                resp = new System.IO.Compression.DeflateStream(resp, System.IO.Compression.CompressionMode.Decompress);
            }

            return new ResRequest() { result = new System.IO.StreamReader(resp, System.Text.Encoding.UTF8).ReadToEnd(), cookies = response.Cookies, cstring = cookiestring(response.Cookies) };
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:50:28+00:00Added an answer on June 16, 2026 at 4:50 am

    So does it hang on req.GetRequestStream() every time, or does it work “a few tries” and then hang?

    If it works a few times and then hangs, it’s possible that you’re not closing the requests properly, which is causing you to run out of connections. Make sure to Close() and/or Dispose() the HttpWebResponse objects and all of the Streams and Readers that you’re creating.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My matlab code does image processing, and I made matlab function which has 2
For a program of mine I made a small function to clear the various
I made a function which displays date on the webpage,, and i uploaded the
I have made one function in which I am passing a matrix and returning
Hi have made this function which is made to replicate an error that I
I have made a program which is a small library operated via software. When
I made a program which is still in development. I did not declared main
Is it possible that a program which does not kill its threads properly before
Updated below: I have a script which has a function I made that calculates
i Have made a program in c# which show 2 types of form 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.