Object request json always returning NULL in php

1

I'm trying to access a server and send data / receive return on json object with the php language.

<?php header('content-type: application/json; charset=utf-8; Accept:application/json; Accept-Language:en-US');

To start, I configured the header, the first attempt was using file_get_contents :

//Acesso ao web service
$json_string = file_get_contents('https://111.222.333.444/v1/activateCode');

$parsed_json =json_decode($json_string, true);
echo $parsed_json;

//tentativa falhada de decodificar a string em formato utf-8
$parsed_json = utf8_decode($parsed_json);

var_dump($http_response_header);

return is NULL , then the 2nd was:

//url com declaracao de variaveis
$url="https://111.222.333.444/v1/activateCode?code=0000002381237220&amount=10.00&upc=799366838258&transactionID=1317828766162&dateTime=2015-05-28T11:32:46.162Z";

//  Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);

// Will dump a beauty json :3
var_dump(json_decode($result, true));
$result = utf8_decode($result);

Return NULL too ... then the 3rd was:

//Acesso ao web service
$json_string = file_get_contents('https://111.222.333.444/v1/activateCode');

$parsed_json =json_decode($json_string, true);

//declarações das variaveis do activateCode
$code = "0000002381237220";
$amount = "10.00";
$upc = 799366838258;
$transactionID = 1317828766162;
$dateTime = "2015-05-28T11:32:46.162Z";
$retailerName = "XYZ";

if( is_null($parsed_json) ){
    // Invalid JSON, don't need to keep on working on it
    echo "<br/>======INICIO NULO=======<br/>";
    echo "codigo nulo";
    echo "<br/>======FIM NULO=======<br/>";
}else{
    // Read data
    echo "<br/>=======RETORNO DA TRANSAÇAO============<br/>";
    echo "RetailTransactionRequest is:";
    echo $parsed_json->alerts[0]->code;
    echo $parsed_json->alerts[0]->amount;
    echo $parsed_json->alerts[0]->upc;
    echo $parsed_json->alerts[0]->transactionID;
    echo $parsed_json->alerts[0]->dateTime;
    echo $parsed_json->alerts[0]->retailerName;
}

That returns only the phrase: >=======RETORNO DA TRANSAÇAO============<br/>RetailTransactionRequest is: with no variable returning from the server ... and another there in the last part already tried to set the $ of the call of the variable (example echo $parsed_json->alerts[0]->$upc; ) even so, without return. The server access happens ... but I only get NULL , I want to know how to proceed ... thanks.

    
asked by anonymous 29.05.2015 / 03:12

0 answers