远程服务器返回错误:(401)未授权(Snom D375)

时间:2016-12-22 09:33:50

标签: c# http-status-code-401 unauthorized

我尝试使用C#Programm远程控制我的snom手机(D375)。这是远程拨号的代码:

     string httpCallCommand = string.Format(
        HTTP_SNOM_CALL_COMMAND,
        Credentials.Instance.PhoneUri.ToString(),
        CALL_COMMAND,
        number,
        MY_NUMBER);

     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(httpCallCommand);
     request.Credentials = new NetworkCredential(Credentials.Instance.User, Credentials.Instance.Password);

     try
     {
        request.GetResponse();
     }
     catch (Exception e)
     {
        if (((WebException)e).Status == WebExceptionStatus.ConnectionClosed)
        {
           // Do nothing because it's normal for the Snom telephone to not answer on this request.
        }
        else if (e.Message.Contains("401"))
        {
           MessageHelper.MessageBoxService.ShowOnTop(
              MessageType.Error,
              MessageHelper.WrongSettingsMessage(true, true, true, ConnectionType.WRONG_CREDENTIALS));
           ClassLogger.Info(LogMessages.WrongCredentials, e.ToString());
        }
        else
        {
           MessageHelper.MessageBoxService.ShowOnTop(
              MessageType.Error,
              MessageHelper.WrongSettingsMessage(true, true, true, ConnectionType.NO_CONNECTION));
           ClassLogger.Info(LogMessages.NoConnection, e.ToString());
        }
     }

呼叫通过,但我也从request.GetResponse();获得“远程服务器返回错误:(401)未授权”。手机上的身份验证方案设置为“基本”。 我无法弄清楚为什么我会得到例外。 如果需要,可以使用以下语法信息http://wiki.snom.com/FAQ/Can_I_control_my_snom_phone_remotely

0 个答案:

没有答案