【问题标题】:Connecting to RETS Servers with UserAgent Requirement连接到具有 UserAgent 要求的 RETS 服务器
【发布时间】:2019-12-29 01:29:06
【问题描述】:

我希望这里有人熟悉称为 RETS 的房地产数据标准。全国房地产经纪人协会提供了一个 dll 用于与他们的服务交互,称为 libRETS,但它不像以前那样受到支持,最近的事件促使我们创建自己的作为替代。出于后勤原因,我们无法在 Core 中执行此操作,并且正在使用当前的 C#.Net 4.7.2。

有 2 或 3 个不同的“安全级别”用于连接到 RETS 服务器,方法是从一个 MLS 到下一个 MLS 以个案为基础。我们可以成功地连接到那些只需要登录名和密码的人,但对那些还需要所谓的 UserAgent 和 UserAgentPassword 的人来说却遇到了困难,这些人必须使用 Md5 加密以某种方式传递。服务器正在返回:

远程服务器返回错误:(401) Unauthorized.

 private WebResponse GetLoginBasicResponse()//*** THIS ONE WORKS ***
    {
        try
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            var request = (HttpWebRequest)WebRequest.Create(new Uri(_cred.loginUri));
            request.Method = "GET";
            request.Headers.Add("RETS-Version", _retsVersion);
            request.Credentials = new NetworkCredential(_login, _password);
            return request.GetResponse();
        }
        catch (Exception ex)
        {
            string ignore = ex.Message;
            return null;
        }
    }
    private WebResponse GetLoginWithUserAgentResponse()//*** THIS ONE DOES NOT WORK ***
    {
        try
        {
           // ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            var request = (HttpWebRequest)WebRequest.Create(new Uri(_cred.loginUri));
            request.Method = "GET";
            request.Headers.Add("RETS-Version", _retsVersion);

            if (!string.IsNullOrEmpty(_cred.userAgent))
            {
                request.UserAgent = Md5(_cred.userAgent + ":" + _cred.userAgentPassword);
                //request.Headers.Add("RETS-UA-Authorization", "Digest " + Md5(_cred.userAgent + ":" + _cred.userAgentPassword));
            }
            request.Credentials = new NetworkCredential(_login, _password);
            return request.GetResponse();
        }
        catch (Exception ex)
        {
            string ignore = ex.Message;
            return null;
        }
    }
    public string Md5(string input) //*** Borrowed this from from .NET Core Project and presume it works
    {
        // Use input string to calculate MD5 hash
        using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
        {
            byte[] inputBytes = Encoding.ASCII.GetBytes(input);
            byte[] hashBytes = md5.ComputeHash(inputBytes);

            // Convert the byte array to hexadecimal string
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                sb.Append(hashBytes[i].ToString("X2"));
            }
            return sb.ToString();
        }
    }

【问题讨论】:

    标签: rets phrets


    【解决方案1】:

    本文档第 20 页介绍了如何构建 UA 标头:https://www.ranww.org/documents/resources/rets_1_8.pdf

    您还需要包括其他一些字段。

    【讨论】:

    • 谢谢!我去看看。
    • 除非我以某种方式过度查看它,否则我无法选择“标记为答案”
    【解决方案2】:

    我们无法在 .NET 中解决该问题,但在 GitHub 中找到了我们正在使用的 .NET Core 项目。 https://github.com/CrestApps/RetsConnector

    此案可以结案

    【讨论】:

      【解决方案3】:

      没有看到“标记为答案”的选项。已尝试过 MS Edge 和 Google Chrome

      【讨论】:

      • 你看到 ✓ 符号了吗?
      • 这是答案左侧上下投票控件下的复选标记。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多