我正在创建一个 WebRequest 以连接到系统,但我在 Visual Studio 中的授权被拒绝。如果我通过 Postman 使用与 NoAuth 设置相同的凭据,它会连接。如何将编程版本设置为具有 NoAuth 凭据?
private HttpWebRequest CreateWebRequest()
{
HttpWebRequest request = null;
if (Reference != null && Password != null)
{
request = (HttpWebRequest)WebRequest.Create($"{Host}/{Path}");
request.Method = "POST";
request.ContentType = "application/xml";
request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
#if DEBUG //Required for the localproxy
IWebProxy webProxy = WebRequest.DefaultWebProxy;
webProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
request.Proxy = webProxy;
#endif
var body = $"v={Version}&ref={Reference}&password={Password}";
var data = Encoding.UTF8.GetBytes(body);
request.ContentLength = data.Length;
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(data, 0, data.Length);
}
}
return request;
}
慕勒3428872
相关分类