我的身份验证是否正确?如何使用RestSharp处理错误
本文关键字:何使用 RestSharp 处理 错误 身份验证 是否 我的 | 更新日期: 2023-09-27 17:58:43
7I有一个使用基本身份验证的页面。我正在尝试验证它,但我一直遇到运行时错误,我不知道如何调试它
在我的服务器上,页面是SSL。我尝试为同一域上的另一个SSL页面创建一个rest客户端。这是个问题吗?
var nclient = new RestClient();
nclient.BaseUrl = "https://www.blank.com/";
nclient.Authenticator = new HttpBasicAuthenticator(id, password);
var nrequest = new RestRequest();
nrequest.Resource = "login.html";
nrequest.AddHeader("Accept", "*/*");
IRestResponse response;
response = nclient.Execute(nrequest);
if (response.ErrorException != null)
{
throw response.ErrorException;
}
错误:
[SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xxx.xxx.xxx.190:443]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +251
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +279
[NullReferenceException: Object reference not set to an instance of an object.]
WebApplication3._default.Button1_Click(Object sender, EventArgs e) in C:'Users''default.aspx.cs:40
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
好的,我想明白了。结果我不得不将页面发布到另一个服务器上。它现在起作用了。