小编Mat*_*ken的帖子

用PHP中的urlfetch替换CURL

我正在为Google App引擎创建一个应用程序,不允许使用CURL.据我所知,urlFetch是最好的选择.

我不知道我是否可以用urlFetch获得相同的结果,但如果有更多经验的人可以帮助我,我真的非常感激.

计划是将以下CURL请求转换为urlFetch.如果有人能指出我正确的方向,或提出更好的选择,我会非常感激.

public function postCall($endpoint, $post_data, $param1, $param2, $json=1, $headers=false) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $this->options['url'].$endpoint);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);

if ($headers && is_array($headers)) {
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}

$post_data['req_token'] = $this->hash($param1, $param2);
curl_setopt($ch, CURLOPT_POST, count($post_data));
if (!$headers) 
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
else
    curl_setopt($ch,CURLOPT_POSTFIELDS, $post_data);
$this->debug('POST params: ' . json_encode($post_data));
$result = curl_exec($ch);
if ($result === false) {
    $this->debug('CURL error: '.curl_error($ch));
    return false;
}
$this->debug('HTTP response code' . curl_getinfo($ch, CURLINFO_HTTP_CODE));
$this->debug('POST return ' . $result);

// close connection
curl_close($ch);

if ($json) …
Run Code Online (Sandbox Code Playgroud)

php google-app-engine curl urlfetch

4
推荐指数
2
解决办法
7986
查看次数

标签 统计

curl ×1

google-app-engine ×1

php ×1

urlfetch ×1