dongzhanlian6289
2013-09-29 14:45
浏览 56
已采纳

在Google App Engine PHP运行时中发送帖子数据和cookiefile

I have a code written in PHP and currently running on my shared hosting. Now I'm going to move it on Google App Engine.

sendRequest() method sends post data and cookies to another website and returns a response.

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;
}

Problems:

  • CURL module is not supported in App Engine
  • tempnam() function is disabled

I've searched a lot, but couldn't find any alternatives. fsockopen() is also disabled.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongye7231 2013-09-30 04:06
    已采纳

    Use the stream context to set the cookies on the request, per the example here.

    Not sure from your code why you want to persist the cookies and for how long - can you use memcache for this purpose instead?

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题