编程语言
首页 > 编程语言> > php – Mailchimp api v1.3返回HTTP / 1.0 302暂时移动

php – Mailchimp api v1.3返回HTTP / 1.0 302暂时移动

作者:互联网

我们的一些客户仍然使用api v1.3.使用MailChimp PHP API Wrapper 1.3.从过去10天开始,由于不明原因停止了工作.我知道我们应该升级到api v3,但有些客户不会看到我们的电子邮件,所以我试图找出可能出错的地方.

我附上调用其服务器的代码部分,返回“http://HTTP/1.0 302 Moved Temporarily Server:AkamaiGHost …”.我正在尝试他们的支持,但即使他们什么都不知道,如果有人能够说出任何意见可能是什么原因可能会有所帮助,所以我可以在他们的支持下进一步推动这一点.

    $dc = "us1";
    if (strstr($this->api_key, "-")) {
        list($key, $dc) = explode("-", $this->api_key, 2);
        if (!$dc)
            $dc = "us1";
    }
    $host = $dc . "." . $this->apiUrl["host"];
    $params["apikey"] = $this->api_key;

    $this->errorMessage = "";
    $this->errorCode = "";
    $sep_changed = false;
    //sigh, apparently some distribs change this to & by default
    if (ini_get("arg_separator.output") != "&") {
        $sep_changed = true;
        $orig_sep = ini_get("arg_separator.output");
        ini_set("arg_separator.output", "&");
    }
    $post_vars = http_build_query($params);
    if ($sep_changed) {
        ini_set("arg_separator.output", $orig_sep);
    }

    $payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
    $payload .= "Host: " . $host . "\r\n";
    $payload .= "User-Agent: MCAPI/" . $this->version . "\r\n";
    $payload .= "Content-type: application/x-www-form-urlencoded\r\n";
    $payload .= "Content-length: " . strlen($post_vars) . "\r\n";
    $payload .= "Connection: close \r\n\r\n";
    $payload .= $post_vars;

    ob_start();
    if ($this->secure) {
        $sock = fsockopen("ssl://" . $host, 443, $errno, $errstr, 30);
    } else {
        $sock = fsockopen($host, 80, $errno, $errstr, 30);
    }
    if (!$sock) {
        $this->errorMessage = "Could not connect (ERR $errno: $errstr)";
        $this->errorCode = "-99";
        ob_end_clean();
        return false;
    }


    $response = "";

    fwrite($sock, $payload);
    stream_set_timeout($sock, $this->timeout);
    $info = stream_get_meta_data($sock);
    while ((!feof($sock)) && (!$info["timed_out"])) {
        $response .= fread($sock, $this->chunkSize);
        $info = stream_get_meta_data($sock);
    }   
    fclose($sock);
    ob_end_clean();

后续代码var_dump($信息);
这个返回数组(7){[“timed_out”] => bool(false)[“blocked”] => bool(true)[“eof”] => bool(false)[“stream_type”] => string(14)“tcp_socket / ssl”[“mode”] => string(2)“r”[“unread_bytes”] => int(0)[“seekable”] =>布尔(假)}

的var_dump($响应);
返回“http://HTTP/1.0 302暂时移动服务器:AkamaiGHost内容长度:0位置:https://us8.api.mailchimp.com/1.3/?output=php&method=listSubscribe日期:星期五,星期五,8月20日21:51:06 GMT连接:关闭”

解决方法:

对我来说设置$this-> secure = true因为类’__construct()而没有完成工作

function __construct($apikey, $secure=false) {
    $this->secure = $secure;
    $this->apiUrl = parse_url("https://api.mailchimp.com/" . $this->version . "/?output=php");
    $this->api_key = $apikey;
}

因此,当您仅使用API​​密钥实例化类时,$secure默认为false.

固定:

$api =新MCAPI($apiKey,true);

希望这有助于你们任何人使用7岁的存储库(包括我自己)…

标签:php,mailchimp
来源: https://codeday.me/bug/20190724/1521298.html