Konsequent einen Status von 0 bekommen, obwohl, wenn ich die URL kopieren und in meinem Browser geschickt, ich rechts zurückAlles falsch mit meinem cURL-Code (http-Status von 0)?
ein JSON-Objekt erhalten<?php
$mainUrl = "https://api.xxxx.com/?";
$co = "xxxxx";
$pa = "xxxx";
$par = "xxxx";
$part= "xxxx";
$partn = "xxxx";
$us= "xxx";
$fields_string;
$fields = array(
'co'=>urlencode($co),
'pa'=>urlencode($pa),
'par'=>urlencode($par),
'part'=>urlencode($part),
'partn'=>urlencode($partn),
'us'=>urlencode($us)
);
foreach($fields as $key=>$value) { $fields_string .= $key . '=' . $value . '&' ;}
$fields_string = rtrim($fields_string, "&");
$fields_string = "?" . $fields_string;
$url = "https://api.xxxxx.com/" . $fields_string;
$request = $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,'3');
$content = trim(curl_exec($ch));
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print $url;
print $http_status;
print $content;
?>
nur einen unabhängigen Randnotiz hinzugefügt haben: PHP hat eine sehr praktische 'http_build_query' Funktion. http://php.net/manual/en/function.http-build-query.php – nico
ist 'https', gibt es einen Fehler zurückgegeben? – ajreal
Yup, nur festgestellt, dass die Überprüfung des Fehlers hilfreich wäre. – Ilya