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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:53:02+00:00 2026-05-24T18:53:02+00:00

Edit: Using: byte[] authBytes = System.Text.Encoding.UTF8.GetBytes(user + : + password); wr.Headers[Authorization] = Basic +

  • 0

Edit: Using:

byte[] authBytes = System.Text.Encoding.UTF8.GetBytes(user + ":" + password);
wr.Headers["Authorization"] = "Basic " + Convert.ToBase64String(authBytes);

Seems to work fine.

I have an application that communicates with a CMS. I’m currently trying to get this client to be able to upload text/xml data to the CMS using a “POST” method.

I can pass this through using curl perfectly fine:

curl -u user:password -H "Content-Type:text/xml" -d "<element>myXML</element>" serverURL

However, trying to use the HttpWebRequest in C# I can’t get the server to return what I want it to. So I fired up Wireshark and had a look at what was actually being passed through, and it’s pretty much identical except for the fact that when using curl I can see:

Authorization: Basic <a bunch of hex>=\r\n
Credentials: user:password

In the HTTP header fields, while in the output from my client, these header fields are simply not present. (“Credentials:” isn’t actually there in plain text, it’s a subtree of “Authorization:” – so I’m not sure where it’s getting it from, but the username and password are correct.)

The C# code I’m trying to use to set the credentials for the webrequest is something like this:

NetworkCredential myCred = new NetworkCredential(
                    user, password, serverURL);

CredentialCache myCache = new CredentialCache();

myCache.Add(new Uri(serverURL), "Basic", myCred);

HttpWebRequest wr = (HttpWebRequest) HttpWebRequest.Create(serverURL);
wr.Credentials = myCache;

I’ve tried just setting the credentials like this too (and without specifying serverURL):

wr.Credentials = new NetworkCredential(user,password,serverURL);

But that still doesn’t make it show up in wireshark. Does anyone have any idea if:

A) That authorization information should actually be in the HTTP header for this to work, and

B) If it is – then how do I make C# put it in? I only seem to be able to find decent examples using the default credentials, which doesn’t apply to what I’m doing.

Thanks in advance.

  • 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-24T18:53:03+00:00Added an answer on May 24, 2026 at 6:53 pm

    .NET’s WebRequest has an infuriating default behavior where it only sends credentials after receiving an HTTP 401 Not Authorized response.

    Manually adding the credentials header (as you’ve done) seems to be the best solution available.

    More details in this post

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that I want to edit using Java. It has
I have a page where the user can edit various content using buttons and
I am converting images to byte array and storing in a text file using
Could somebody tell me how can I convert byte[] to ArrayList by using C#
I need to edit (using javascript) an SVG document embedded in an html page.
I'm using Visual Studio 2008. I'm currently working with WPF and I'm using Edit->Format
Edit: I am using SqlDataAdapters to fill the data sets. Sorry--I should have been
I am using Komodo Edit , a code editor. When I right click on
I've been using Komodo Edit for a small project in Django. The code completion
I have recently been working with Python using Komodo Edit and other simpler editors

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.