mercredi 6 septembre 2017

Laravel 5.4 and HTTP_Request2

So I have already installed pear/http_request2 on my laravel project but can't seem to make it work. What I'm trying is the following code for the Bing Image Search API:

    $request = new \Http_Request2('http://ift.tt/2fvus1a');
    $url = $request->getUrl();

    $headers = array(
        // Request headers
        'Content-Type' => 'multipart/form-data',
        'Ocp-Apim-Subscription-Key' => '{subscription key}',
    );

    $request->setHeader($headers);

    $parameters = array(
        'q' => 'query string',
    );

    $url->setQueryVariables($parameters);

    $request->setMethod(HTTP_Request2::METHOD_POST);

    $request->setBody("{body}");

    try
    {
        $response = $request->send();
        $response->getBody();
    } catch (HttpException $ex) {
        $ex;
    }

Whenever I call it on my controller, I get a "Class 'Http_Request2' not found" error. How, in any way, can I use the pear/http_request2 for my project?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire