Ich evaluiere loader.io für einen Client und ich habe Probleme, die APi richtig zu funktionieren. Ich bin auf PHP 7 http://docs.loader.io/api/v2/post/tests.html#url-optionsLoader.io - PHP, curl und json
Ich bin auf 'Test erstellen' stecken.
Die docs sagen:
curl -X POST -H 'loaderio-auth: API_KEY' -H 'Content-Type: application/json' --data-binary '{"test_type":"cycling", "total": 6000, "duration":60, "urls": [ {"url": "http://gonnacrushya.com"} ]}' https://api.loader.io/v2/tests
Das ist großartig! Wenn ich meinen APi-Schlüssel und die korrekte URL hinzufüge, läuft es gut, der Test wird erstellt.
Buuuut ..
Ich möchte dies über eine Symfony2 App in Ajax tun.
Hier ist, was ich habe, dass der Fehler ist die Rückkehr:
urls param has incorrect format
function myAjaxCalledFunction() {
$test_data = '{"test_type":"cycling", "total": 10, "duration":5, "urls": [{"url": "http://www.my-configured-url.com"}] }';
return $this->doCurlRequest('tests', 'POST', $test_data);
}
public function doCurlRequest($what_call, $request = 'GET', $post_data = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.loader.io/v2/' . $what_call);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('loaderio-auth: ' . $this->loader_api_key));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
$response = curl_exec($ch);
return new Response($response);
}
gibt es eine curl_setopt(), die ich vermisst habe?
I-Tests, die Liste sollte darauf hinweisen, führen Tests ... alle Arbeiten über Ajax und die Funktion oben (ich einige es $ post_data nahm gesetzt Code für die Einfachheit hier) – Beertastic