PHP - 无法通过PHRETS连接到RETS

时间:2017-07-09 16:36:14

标签: php curl rets phrets

我试图通过PHP使用我从这里下载的PHRETS获取我的所有MLS列表:

https://github.com/dangodev/PHRETS-Example/blob/master/lib/phrets.php

我用这个例子将我的列表下载到csv格式:

https://github.com/troydavisson/PHRETS/wiki/Connect,%20download%20listing%20data%20in%20CSV%20format,%20disconnect

我从MLS主板上获得了RETS URL,用户名和密码,但我仍然无法连接。

在此处调用PHRETS库时,我的代码返回false:

require_once("phrets.php");

// start rets connection
$rets = new phRETS;

echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);

if ($connect) {
        echo "  + Connected<br>\n";
}
else {
        echo "  + Not connected:<br>\n";
        print_r($rets->Error());
        exit;
}

当我转到库并查看方法Connect时,该代码在此处返回false:

// make request to Login transaction
        $result =  $this->RETSRequest($this->capability_url['Login']);
        if (!$result) {
            return false;
        }

当我查看我的RETSRequest方法时,它在这里返回false,因为响应代码是0而不是200

if ($response_code != 200) {
            $this->set_error_info("http", $response_code, $response_body);
            return false;
        }

这是尝试连接的地方:

if ($this->ua_auth == true) {
            $session_id_to_calculate_with = "";

            // calculate RETS-UA-Authorization header
            $ua_a1 = md5($this->static_headers['User-Agent'] .':'. $this->ua_pwd);
            $session_id_to_calculate_with = ($this->use_interealty_ua_auth == true) ? "" : $this->session_id;
            $ua_dig_resp = md5(trim($ua_a1) .':'. trim($this->request_id) .':'. trim($session_id_to_calculate_with) .':'. trim($this->static_headers['RETS-Version']));
            $request_headers .= "RETS-UA-Authorization: Digest {$ua_dig_resp}\r\n";
        }

        $this->last_request_url = $request_url;
        curl_setopt($this->ch, CURLOPT_URL, $request_url);

        curl_setopt($this->ch, CURLOPT_HTTPHEADER, array(trim($request_headers)));
        // do it
        $response_body = curl_exec($this->ch);
        $response_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

为什么我无法连接?

我可以使用网址,用户名和密码通过http://retsmd.com登录。我真的需要以CSV格式获取我的列表。

请帮助

我的服务器上安装了curl,我检查了这个方法:

Check to see if cURL is installed locally?

2 个答案:

答案 0 :(得分:3)

响应代码0通常表示您的服务器无法打开与服务器的连接,可能是由于您与他们之间的防火墙问题。一些RETS服务器仍然在端口6103上运行,因此如果您的服务器(托管公司等)阻止在该端口上打开出站连接,这可能是您所看到的原因。

我建议您尝试从没有任何连接限制的其他服务器或计算机中获取代码示例。您还可以尝试使用https://retsmd.com/auth来验证您获得的凭据是否有效(假设您的本地环境具有运行PHRETS所需的内容)。

答案 1 :(得分:1)

添加到troydavisson的答案,

您可以添加以下额外的代码行来获取连接日志以检查问题。

// start rets connection
$rets = new phRETS;
$rets->SetParam('debug_mode', true);//extra line of code to get log

您将获得rets_debug.txt文件的完整日志。

相关问题