Organizational Research By

Surprising Reserch Topic

replacing curl with urlfetch in php using -'php,google-app-engine,curl,urlfetch'

replacing curl with urlfetch in php  using -'php,google-app-engine,curl,urlfetch'

I'm creating an application for Google App engine, where CURL isn't allowed.
As far as I know, urlFetch is the best alternative.

I don't know if I can achieve the same result with urlFetch, but I would really, really appreciate it if anyone with more experience could help me out.

The plan was to convert the following CURL requests to urlFetch. If anyone can point me in the right direction, or propose a better alternative, I'd greatly appreciate it.

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

if ($json)
    return json_decode(utf8_encode($result), true);
    return $result;}


asked Sep 7, 2015 by rajesh
0 votes

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.