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($info);
此返回数组(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"]=> bool(false) }
var_dump($response);
这将返回“ http://HTTP/1.0 302 已临时移动 服务器:AkamaiGHost 内容长度:0 位置:https ://us8.api.mailchimp.com/1.3/?output=php&method=listSubscribe日期:2018 年 8 月 10 日星期五格林威治标准时间 21:51:06 连接:关闭”
解决方案
对我来说,由于类' __construct()设置$this->secure = true
没有完成这项工作
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 = new MCAPI($apiKey, true);
希望这可以帮助你们中的任何一个使用 7 年历史的存储库(包括我自己)的人......
推荐阅读
- node.js - 如何打印整个json数据
- javascript - javascript - 加入2个日期数组
- image - 在 vuetify 中搜索左侧浮动的图像样本
- linux - 等到第一个 .jar 文件完成后再在 for 循环中执行第二个 .jar 文件
- node.js - NodeJS 和 ECMA 脚本版本
- ocaml - 如何编译使用 JsooTop 模块的文件?
- python - 从数据框中提取子集
- angular - 离子侧菜单不显示?
- java - 膨胀类 android.view.InflateException 时出错,找不到类 java.lang.ClassNotFoundException
- reactjs - 使用函数渲染反应 Typescript 无限循环