我有一个用PHP编写的代码,目前正在我的共享主机上运行。现在我要把它移到Google App Engine上。
sendRequest()
方法将帖子数据和 cookie 发送到另一个网站并返回响应。
private function sendRequest($url, array $data = array()) {
$ch = curl_init(self::URL_BASE);
$curlConfig = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_COOKIE => "user_name=" . $this->username . "; user_password=" . md5($this->password));
if ($url == self::URL_LOGIN) {
$this->cookieFile = tempnam("/tmp", "CURLCOOKIE");
$curlConfig[CURLOPT_COOKIEJAR] = $this->cookieFile;
} else {
$curlConfig[CURLOPT_COOKIEFILE] = $this->cookieFile;
}
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
问题:
- 应用引擎不支持 CURL 模块
-
tempnam()
功能已禁用
我搜索了很多,但找不到任何替代方案。 fsockopen()
也被禁用。
根据此处的示例,使用流上下文在请求上设置 Cookie。
从您的代码中不确定为什么要保留 cookie 以及保留多长时间 - 您可以使用 memcache 来实现此目的吗?