Jump to content
MasterWalter

PHP API TOKEN

Recommended Posts

MasterWalter

Boas

Em PHP necessito utilizar um token depois de fazer um Post  até agora já consegui o resultado e receber o token.

no webbrowser mas não consigo fazer echo do  $Token a variavel fica vazia

Tenho exemplo abaixo.

Quando ativo a linha

$result= json_decode ($result) fico sem resultado no webbrowser.

 

<?php

    ini_set('display_errors', 'off');
    error_reporting(E_ALL | E_STRICT);

	// CODIGO QUE ESTAMOS A TRABALHAR DE TESTE

	// CREATE TOKEN
	$url = 'https://urlservidor';

    $ch = curl_init($url);

	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  
    curl_setopt($ch, CURLOPT_POST, 1);
 
   	curl_setopt($ch, CURLOPT_POSTFIELDS,$jsonData);
 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    										'Content-Type: application/json',
    										'Authorization: Basic '. base64_encode("user:pass"),
    										)
	);

	curl_setopt($ch, CURLOPT_POST,1);
	curl_setopt($ch, CURLOPT_HEADER,1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   
    $result = curl_exec($ch);
	
	// $result = json_decode ($result);

  	  	 
	$token = ($result)->token;
	 
	echo $token;

	echo '<pre>';

	print_r($result);

 

 

HTTP/1.1 200 OK Cache-Control: no-cache Content-Length: 117 Content-Type: application/json; charset=utf-8 ETag: W/"75-tSEeQ0X/aprG22KPQ4xOKQ" Vary: Accept-Encoding X-FM-Data-Access-Token: c7ad160ee9034f9490f66f59bdc1684d30e33b9d413bc85c73c X-Powered-By: ARR/3.0 X-Powered-By: ASP.NET X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Date: Wed, 18 Jul 2018 23:48:38 GMT {"response":{"token":"c7ad160ee9034f9490f66f59bdc1684d30e33b9d413bc85c73c"},"messages":[{"code":"0","message":"OK"}]}

 

Obrigado

 

Pedido ajuda em PHP...

 

 

 

Edited by MasterWalter

Share this post


Link to post
Share on other sites
elitepc
On 7/19/2018 at 12:54 AM, MasterWalter said:

curl_setopt($ch, CURLOPT_HEADER,1);

Eu começava o teste por passar este parâmetro a 0 e colocava o json_decode no result.

Porque é que colocaste a 1?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.