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

  • SEARCH
  • Home
  • 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 8370315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:53:11+00:00 2026-06-09T13:53:11+00:00

Following on from the post How to create a simple proxy in C#? I

  • 0

Following on from the post How to create a simple proxy in C#? I have been playing around with implementing a basic proxy.

Where I am getting stuck and confused is trying to issue a WebRequest with the information provided in the original request.

Using the following code.

WebRequest webRequest = WebRequest.Create("http://www.google.com");

(webRequest as HttpWebRequest).UserAgent = "MOZILLA/5.0 (WINDOWS NT 6.1; WOW64) APPLEWEBKIT/537.1 (KHTML, LIKE GECKO) CHROME/21.0.1180.75 SAFARI/537.1";
webRequest.Method = "GET";

WebResponse webResponse = webRequest.GetResponse();
Stream responseStream = webResponse.GetResponseStream();
byte[] responseBytes = responseStream.ReadFully();

I can successfully issue a request and return the page content.

However when I put it inside a Proxy request (IE: TcpListener) like such.

TcpListener _listener = new TcpListener(IPAddress.Any, 1234);
this._listener.Start();
byte[] bytes = new byte[1024];
while (true)
{
    TcpClient client = this._listener.AcceptTcpClient();
    NetworkStream networkStream = client.GetStream();
    int i = networkStream.Read(bytes, 0, bytes.Length);
    while (i != 0)
    {
        string data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
        RequestHeader header = new RequestHeader(data.ToUpper());
        WebRequest webRequest = WebRequest.Create(header.URL);
        (webRequest as HttpWebRequest).UserAgent = header.UserAgent;
        webRequest.Method = "GET";
        WebResponse webResponse = webRequest.GetResponse(); //It gets here and never returns
        Stream responseStream = webResponse.GetResponseStream();
        byte[] responseBytes = responseStream.ReadFully();
        networkStream.Write(responseBytes, 0, responseBytes.Length);
        i = networkStream.Read(bytes, 0, bytes.Length);
    }
    client.Close();
}

It blocks at the line WebResponse webResponse = webRequest.GetResponse(); and never returns.

This has definitely got nothing to do with the data provided by the RequestHeader class I created as I’ve also tried hardcoding the values.

I’m assuming I’m missing something fundamental about the way sockets work in such a scenario and the approach required. Hopefully someone can clarify for me.

  • 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-09T13:53:12+00:00Added an answer on June 9, 2026 at 1:53 pm

    So it turned out to be a proxy issue.

    Basically for testing I needed to set the machine proxy to 127.0.0.1:1234 or similar.

    This in turn was being used in the default settings when initializing a WebRequest.

    So all I needed to do in the end was the following to bypass the proxy.

    (webRequest as HttpWebRequest).UserAgent = header.UserAgent;
    webRequest.Method = "GET";
    webRequest.Proxy = null; //Adding this line cleared the proxy.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using the following code to obtain a simple web response from
Following on from a post I made earlier, I am making progress with what
Following on from my other post about primary keys I am wondering if there
I am using the following code to post data from an android app to
I'm following the instructions on using xsi:type from this oft-cited blog post: http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-xsitype.html Basically
I have noted the following from a website: The JVM HotSpot memory is split
I'm getting the following from a third party library (one example): @%SystemRoot%\SomePath\SomeFile.Dll,-203 I know
I have a simple form right now: <form action='<? echo $PHP_SELF;?>' method='POST'> Username:<input type='text'
I'm following Django documentation here in order to achieve a simple objective: Create a
I am trying to create a very simple post-commit hook for a repository I

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.