.Net WebClient类中的curl -u等效项 [英] curl -u equivalent in .Net WebClient class
问题描述
这个问题解释了所有这些,但是这里有一些更多信息。我正在尝试将4sq api与C#结合使用,并且需要在每个请求中发送用户名密码对。 API文档说 curl -u user:pass可以完成这项工作,但是如何使用WebClient呢?没有时间检查流量,也许有人知道它。
The question explains it all but here is some more info. I am trying to use 4sq api with C# and need to send username password pair in every request. The API documentations says that "curl -u user:pass" does the job but how can I do it with WebClient? Don't have time to inspect the traffic, maybe someone knows about it...
WebClient.Credential不能正常工作。
WebClient.Credential doesn't work by the way.
谢谢。
推荐答案
这是解决方案:
webRequest.Headers.Add( Authorization, Basic + Convert.ToBase64String(authbytes));
webRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(authbytes));
authBytes是将密码转换为字节数组。
authBytes is the password converted to byte array.
这篇关于.Net WebClient类中的curl -u等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!