curl -u equivalent in .Net WebClient class

一曲冷凌霜 提交于 2019-12-22 11:26:27

问题


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 doesn't work by the way.

Thanks.


回答1:


This is the solution:

webRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(authbytes));

authBytes is the password converted to byte array.




回答2:


Try using a CredentialCache



来源:https://stackoverflow.com/questions/3996771/curl-u-equivalent-in-net-webclient-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!