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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:52:11+00:00 2026-05-26T15:52:11+00:00

I have a custom HTTP class for the service I am using. Eventually it

  • 0

I have a custom HTTP class for the service I am using. Eventually it will contain service specific requests in the form of methods. What I need to do is set the credentials of the proxy provided by the user, for example if the user has a proxy list.

Below is my code. I’ve commented the part I need to set credentials. I’ve looked at the iCredentials class on MSDN but I can’t see how to set them from a string.

class RequestClass
{
    private CookieContainer cookieJar;
    private WebProxy proxy = null;

    public RequestClass()
    {
        this.cookieJar = new CookieContainer();
    }

    public RequestClass(String proxyURL, int port)
    {
        this.proxy = new WebProxy(proxyURL, port);
    }

    public RequestClass(String proxyURL, int port, String username, String password)
    {
        this.proxy = new WebProxy(proxyURL, port);
        // Need to set them here
    }

    // HTTP Get Request
    public HttpWebResponse getRequest(String url, NameValueCollection headers)
    {
        HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(url);
        getRequest.Method = "GET";
        getRequest.CookieContainer = cookieJar;

        foreach (String key in headers.Keys)
        {
            getRequest.Headers.Add(key, headers[key]);
        }

        return (HttpWebResponse)getRequest.GetResponse();
    }

    // HTTP Post Request
    public HttpWebResponse postRequest(String url, String postData, NameValueCollection headers)
    {
        byte[] postBytes = Encoding.ASCII.GetBytes(postData);

        HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(url);
        postRequest.Method = "POST";
        postRequest.CookieContainer = cookieJar;
        postRequest.ContentLength = postBytes.Length;
        postRequest.ProtocolVersion = HttpVersion.Version10;

        foreach(String key in headers.Keys)
        {
            postRequest.Headers.Add(key, headers[key]);
        }

        Stream postRequestStream = postRequest.GetRequestStream();

        postRequestStream.Write(postBytes, 0, postBytes.Length);
        postRequestStream.Close();

        return (HttpWebResponse)postRequest.GetResponse();
    }
}

}

  • 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-26T15:52:11+00:00Added an answer on May 26, 2026 at 3:52 pm

    I think this should work:

    public RequestClass(String proxyURL, int port, String username, String password)
    {
        //Validate proxy address
        var proxyURI = new Uri(string.Format("{0}:{1}", proxyURL, port));
    
        //Set credentials
        ICredentials credentials = new NetworkCredential(username, password);
    
        //Set proxy
        this.proxy =  = new WebProxy(proxyURI, true, null, credentials );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today, I have a problem with hosting my custom service host using custom binding
We have a Web Service implementation that throws a custom SecurityException . public class
I have a few custom UITableViewCells - http://img11.imageshack.us/i/customfacilitiescell.png/ which are added to this UIViewController
We have an HttpHandler that deals directly with binary posts over HTTP from custom
We have custom headers in the Silverlight DataGrid using the ContentTemplate. We've got a
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
I have a few models that need to have custom find conditions placed on
I have a custom class declared as follows (in vb.net) <Serializable()> Public Class NumInfo
I need to create a mule service that will POST data to a web
I have a WCF service with custom binding, hosted in IIS (IIS Express in

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.