I new to C# but been working with PHP for years and decided to try proper programming :)

I want to create a simple proxy to add or remove certain http headers. My plan was to use HttpListener to catch the request by the browser then edit headers I needed then use HttpWebRequest/Response to send and receive then edit the response if need be.

But before I start filtering the data I need to know how to or if it is possible to send the edited response back to the web browser and if im doing this correctly???

Here my code thus far just to get the request method & url for the HttpWebRequest, how do I make it threaded to handle multiple connecitons.

using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            int port = 80;
            string prefix = string.Format("http://*:{0}/", port);

            // Create a listener.
            HttpListener listener = new HttpListener();
            // Note: The GetContext method blocks while waiting for a request. 
            HttpListenerContext context = listener.GetContext();
            HttpListenerRequest request = context.Request;

            // Display the URL used by the client.
            Console.WriteLine("URL: {0}", request.Url);
            Console.WriteLine("Original URL: {0}", request.Url.OriginalString);
            Console.WriteLine("Raw URL: {0}", request.RawUrl);
            Console.WriteLine("Query URL: {0}", request.Url.Query);


Also simple question about:

Console.WriteLine("Raw URL: {0}", request.RawUrl);

How do I convert to a string and whats the "{0}" about?

Thanks for helping a newb!

Edited 6 Years Ago by arbme: n/a

This article has been dead for over six months. Start a new discussion instead.