cURL with user authentication in C#

落爺英雄遲暮 提交于 2019-11-27 12:30:24

HTTP Basic authentication requies everything after "Basic " to be Base64-encoded, so try

request.Headers["Authorization"] = "Basic " + 
    Convert.ToBase64String(Encoding.ASCII.GetBytes(authInfo));

The solution to my question was changing the ContentType property. If I change the ContentType to

request.ContentType = "text/xml";

the request works in both cases, if I also convert the authInfo to a Base64String in the last example like Anton Gogolev suggested.

Using:

request.ContentType = "application/xml";

request.Credentials = new NetworkCredential(GEOSERVER_USER, GEOSERVER_PASSWD);

also works. The second sets authentication information.

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