【问题标题】:Send post data and cookiefile in Google App Engine PHP runtime在 Google App Engine PHP 运行时发送帖子数据和 cookie 文件
【发布时间】:2013-10-05 10:32:03
【问题描述】:

我有一个用 PHP 编写的代码,目前在我的共享主机上运行。现在我要把它移到 Google App Engine 上。

sendRequest() 方法将 post 数据和 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;
}

问题:

  • App Engine 不支持 CURL 模块
  • tempnam() 功能被禁用

我搜索了很多,但找不到任何替代方案。 fsockopen() 也被禁用。

【问题讨论】:

    标签: php google-app-engine post cookies curl


    【解决方案1】:

    根据示例here,使用流上下文设置请求的cookie。

    从您的代码中不确定为什么要保留 cookie 以及保留多长时间 - 您可以使用 memcache 来代替吗?

    【讨论】:

      猜你喜欢
      • 2014-03-26
      • 1970-01-01
      • 2015-11-08
      • 2010-10-27
      • 1970-01-01
      • 2015-02-25
      • 2019-10-31
      • 1970-01-01
      • 2016-04-04
      相关资源
      最近更新 更多