C# 我的身份验证正确吗?如何使用RestSharp处理错误?

C# 我的身份验证正确吗?如何使用RestSharp处理错误?,c#,restsharp,C#,Restsharp,7我有一个使用基本身份验证的页面。我正在尝试对它进行身份验证,但我不断收到运行时错误,我不确定如何找出如何调试它 在我的服务器上,页面是SSL。我尝试创建一个rest客户机到同一域上的另一个SSL页面。这是个问题吗 var nclient = new RestClient(); nclient.BaseUrl = "https://www.blank.com/"; nclient.Authenticator = new HttpBasicAuthenticator(id, password);

7我有一个使用基本身份验证的页面。我正在尝试对它进行身份验证,但我不断收到运行时错误,我不确定如何找出如何调试它

在我的服务器上,页面是SSL。我尝试创建一个rest客户机到同一域上的另一个SSL页面。这是个问题吗

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

好吧,我知道了。结果是我不得不将页面发布到另一台服务器。它正在工作。

您遇到了什么错误?您没有发布错误,您发布了一条消息,告诉您没有显示错误。按照它的说明获取实际的错误,然后发布。这不是错误,这是IIS说有错误,但它不会告诉你错误的细节。您需要按照说明查看实际错误是什么。在本地计算机上运行代码或按照消息中的说明操作。当我在本地计算机上运行代码时,它100%正常运行。它在发布的服务器上死亡。