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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:00:02+00:00 2026-06-02T13:00:02+00:00

I have a class that uses a HttpWebRequest to post some XML and recieve

  • 0

I have a class that uses a HttpWebRequest to post some XML and recieve some XML back. It all works great on a windows application but when I use it in an ASP.Net web side I get as WebException “Unable to connect to the remote server”. I think that it is something to do with going through my companies Proxy. But am not sure of how to set up the Credentials so that it will work in the web pages. Below is the code that posts the XML (m_Credentials has been set by using “CredentialCache.DefaultCredentials”:

    private string PostData(string url, string postData)
    {
      HttpWebRequest request=null;

      Uri uri = new Uri(url);
      request = (HttpWebRequest) WebRequest.Create(uri);
      request.Method = "POST";
      request.ContentType = "application/x-www-form-urlencoded";
      request.ContentLength = postData.Length;

      // Tell it to use our credentials else we may not get through 
      if (m_Credentials != null)
      {
        request.Proxy.Credentials = m_Credentials;
      }


      using(Stream writeStream = request.GetRequestStream())
      {
        UTF8Encoding encoding = new UTF8Encoding();
        byte[] bytes = encoding.GetBytes(postData);
        writeStream.Write(bytes, 0, bytes.Length);
      }

      string result=string.Empty;
      using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
      {
        using (Stream responseStream = response.GetResponseStream())
        {
          using (StreamReader readStream = new StreamReader (responseStream, Encoding.UTF8))
          {
            result = readStream.ReadToEnd();
          }
        }
      }
      return result;
    }
  • 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-02T13:00:05+00:00Added an answer on June 2, 2026 at 1:00 pm

    Below is the code that posts the XML (m_Credentials has been set by
    using “CredentialCache.DefaultCredentials”

    That might be the issue. On a Windows app, the credentials used to authenticate with the proxy will be the ones of the current logged in user. On the ASP.NET app, the credentials used will be the ones from the local service account running the asp.net process. One option is to set the credentials to an actual valid account on your network.

    request.Credentials = new NetworkCredential("username","password","domain");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that uses sudzc. All works fine, with NSLog I can
Let's say that I have class , that uses some functionality of dict .
I have a Class that uses a dictionary to store some data. But I
I have a class that uses 5.3 feature anonymous function ( https://github.com/JeffreyWay/Easy-WordPress-Custom-Post-Types/blob/master/jw_custom_posts.php ), but
I have a controller class that uses asynchronous calls to perform some network operations.
I have class that uses hibernate, I have included all required jars to classpath
I have a class that uses XML and reflection to return Object s to
I have a class 'Data' that uses a getter to access some array. If
I have a class that uses linq to access the database. Some methods call
I have a class that uses XStream and is used as a transfer format

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.