[英]Converting curl command to C# code
I am having problems converting a curl command to c# code. 我在将curl命令转换为C#代码时遇到问题。
I have been given a curl command which includes an API key as follows: 我得到了一个curl命令,其中包括一个API密钥,如下所示:
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: 当我在Fiddler中观看此调用时,我可以看到如下所示的标头值:
Authorization: Basic eDo0NTljNGRhNjQwMWQzOWJiZjkzMjdlZTE3MTc1ZTI1Yw==
So, the curl command is working perfectly... But I cannot replicate it in c# code 因此,curl命令运行得很好...但是我无法在c#代码中复制它
I don't understand how the x:459c4da6401d39bbf9327ee17175e25c
has changed to Authorization: Basic eDo0NTljNGRhNjQwMWQzOWJiZjkzMjdlZTE3MTc1ZTI1Yw==
我不了解
x:459c4da6401d39bbf9327ee17175e25c
如何更改为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. 随后,我很困惑如何使我的C#代码从API密钥更改为我在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 谢谢
eDo0NTljNGRhNjQwMWQzOWJiZjkzMjdlZTE3MTc1ZTI1Yw==
is the base64 encode of x:459c4da6401d39bbf9327ee17175e25c
. eDo0NTljNGRhNjQwMWQzOWJiZjkzMjdlZTE3MTc1ZTI1Yw==
是x:459c4da6401d39bbf9327ee17175e25c
的base64编码。 Try online here . 在这里尝试在线 。
And the request header for Authorization will be the base64 string that you encoded above. 授权的请求标头将是您上面编码的base64字符串。
httpWebRequest.Headers.Add("Authorization", "Basic eDo0NTljNGRhNjQwMWQzOWJiZjkzMjdlZTE3MTc1ZTI1Yw==");
You can use this link to perform base64 encoding/decoding in c#
. 您可以使用此链接在
c#
执行base64编码/解码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.