0

I am having problems converting a curl command to c# code.

I have been given a curl command which includes an API key as follows:

curl -k -u x:459c4da6401d39bbf9327ee17175e25c 
        -H "Content-Type: application/json" https://disney.com/v1/services.json

When I watch this call in Fiddler I can see a header value that looks like this:

Authorization: Basic eDo0NTljNGRhNjQwMWQzOWJiZjkzMjdlZTE3MTc1ZTI1Yw==

So, the curl command is working perfectly... But I cannot replicate it in c# code

I don't understand how the x:459c4da6401d39bbf9327ee17175e25c has changed to Authorization: Basic eDo0NTljNGRhNjQwMWQzOWJiZjkzMjdlZTE3MTc1ZTI1Yw==

And subsequently, I am confused how to get my c# code to change from the API key to what I am seeing in Fiddler.

When I use this code to add a header the authorisation fails:

httpWebRequest.Headers.Add("Authorization", "459c4da6401d39bbf9327ee17175e25c");

I have also tried:

httpWebRequest.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes("459c4da6401d39bbf9327ee17175e25c"));

But that produces a header value of this:

Authorization: Basic NDU5YzRkYTY0MDFkMzliYmY5MzI3ZWUxNzE3NWUyNWM=

Can anyone help please?

Thanks

1 Answer 1

1

eDo0NTljNGRhNjQwMWQzOWJiZjkzMjdlZTE3MTc1ZTI1Yw== is the base64 encode of x:459c4da6401d39bbf9327ee17175e25c. Try online here.

And the request header for Authorization will be the base64 string that you encoded above.

httpWebRequest.Headers.Add("Authorization", "Basic eDo0NTljNGRhNjQwMWQzOWJiZjkzMjdlZTE3MTc1ZTI1Yw==");

You can use this link to perform base64 encoding/decoding in c#.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks! so, I was an idiot and I was encoding without the "x:" which I thought was a curl parameter....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.