lundi 30 janvier 2017

How can I add the ' character into a string representing the JSON for a WS call in PHP?

I am an abslolute beginner in PHP and moreover in Laravel framework (I came from Java).

I am finding the following problem trying to perform a Guzzle call to a REST web service:

if I do it using mocked creadential data it works fine:

    $response = $client->get('http://localhost:8080/Extranet/login',
        [
            'auth' => [
                'nobili.andrea@gmail.com',
                'pswd'
            ]
        ]);

    $dettagliLogin = json_decode($response->getBody());

    \Log::info('response: '.(json_encode($dettagliLogin)));

But trying to do in this way

    $response = $client->get('http://localhost:8080/Extranet/login',
        [
            'auth' => [
                //'nobili.andrea@gmail.com',
                //'pswd'
                $credentials['email'] . ','
                .$credentials['password']
            ]
        ]);

    $dettagliLogin = json_decode($response->getBody());

    \Log::info('response: '.(json_encode($dettagliLogin)));

it goes into error.

I think that maybe the problem could depend by the fact that the mocked credential contain the ' before and after username and password fields:

'nobili.andrea@gmail.com',
'pswd'

How can I insert it in my dynamic version of code?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire