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 3681708
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:43:01+00:00 2026-05-19T03:43:01+00:00

I’m trying create a small http proxy service. This is not working so well.

  • 0

I’m trying create a small http proxy service. This is not working so well. It is able to serve HTML okayish, however it chokes up on images. That is, some images.

Sending in a url through my proxy yields 19.4 kb in the response (according to firebug)
Visiting that url directly also yields 19.4 kb in the response, again according to firebug. The difference is, it doesn’t show up when I put it through my proxy, but it does when I browse directly.

A completely different url works just fine. Does anyone have any idea?

private void DoProxy()
{
    var http = listener.GetContext();
    string url = http.Request.QueryString["url"];
    WebRequest request = HttpWebRequest.Create(url);
    WebResponse response = request.GetResponse();
    http.Response.ContentType = response.ContentType;

    byte[] content;
    using (Stream responseStream = response.GetResponseStream())
        content = ReadAll(responseStream);
    http.Response.ContentLength64 = content.Length;
    http.Response.OutputStream.Write(content, 0, content.Length);
    http.Response.Close();
}

private byte[] ReadAll(Stream stream)
{
    IList<byte> array = new List<byte>();
    int b;
    while ((b = stream.ReadByte()) != -1)
        array.Add(Convert.ToByte(b));
    return array.ToArray();
}
  • 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-05-19T03:43:01+00:00Added an answer on May 19, 2026 at 3:43 am

    I would try and flush/close the OutputStream before you close the response.

    Also as a second suggestion have a look at the HTTP traffic from the original site and then through your proxy site using an HTTP debugger like Fiddler – there must be a difference when using your proxy.

    Also to make the ReadAll method more effective, in general I would avoid to load the full content into memory, because this will blow up on huge files – just stream them directly from the input stream to the output stream. If you still want to use byte arrays consider the following (untested but should work):

    private byte[] ReadAll(Stream stream)
    {
        byte[] buffer = new byte[8192];
        int bytesRead = 1;
        List<byte> arrayList = new List<byte>();
    
        while (bytesRead > 0)
        {
            bytesRead = stream.Read(buffer, 0, buffer.Length);
            arrayList.AddRange(new ArraySegment<byte>(buffer, 0, bytesRead).Array);
        }
        return arrayList.ToArray();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.