Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]HTTP request API
#11

No, no. Your code is wrong.
You must pass three parameters, but you passed four parameters.

PHP Code:
$client->request('GET''/get', ['query' => ['foo' => 'bar']]); 
Reply
#12

Quote:By default, CURLRequest will throw HTTPException if the HTTP code returned is greater than or equal to 400. If you want to get the response, see the http_errors option.
https://codeigniter4.github.io/CodeIgnit...g-requests
Reply
#13

(01-16-2024, 12:59 AM)kenjis Wrote: No, no. Your code is wrong.
You must pass three parameters, but you passed four parameters.

PHP Code:
$client->request('GET''/get', ['query' => ['foo' => 'bar']]); 

the request requires two parameters start date and end date , i try this :

Code:
  public function getTransazionidispenser()
  {
   
    $uri = 'https://www.sinapsiweb.com/API/SinapsiParsedAPI/GetTransazioni';
    //$uri = 'https://www.sinapsiweb.com/API/SinapsiParsedAPI/GetTransazioni?dataDa=10/01/2024 00:00:00&dataA=15/01/2024 00:00:00';

    $client = \Config\Services::curlrequest();



    $response = $client->request('GET', $uri ,
                                                [
                                                  'auth' => ['xxx', 'xxx', 'basic']
                                                ],
                                               
                                                [
                                                  'query' =>  [
                                                                'dataDa' => '10/01/2024 00:00:00'
                                                              ]
                                                ],

                                                [
                                                  'query' =>  [
                                                                'dataA' => '15/01/2024 00:00:00'
                                                              ]
                                                ]

                                );


    $body = $response->getBody();

    $res = json_decode($body);

    foreach($res as $v){
     
      echo '<pre>';
      print_r($v);
   
    }

  }

whith same 500 error , than i don't understand how can i get curl error , with try catch ? if else?
Reply
#14

If you want to see the response, not HTTPException,
see https://codeigniter4.github.io/CodeIgnit...ttp-errors
Reply
#15

You passed 5 paramters to request() method, but you must pass 3 parameters.
The third parameter is an array.

PHP Code:
    $response $client->request('GET'$uri ,
                                                [
                                                  'auth' => ['xxx''xxx''basic']
                                                ],
                                              
                                                
[
                                                  'query' =>  [
                                                                'dataDa' => '10/01/2024 00:00:00'
                                                              ]
                                                ],

                                                [
                                                  'query' =>  [
                                                                'dataA' => '15/01/2024 00:00:00'
                                                              ]
                                                ]

                                ); 
Reply
#16

(01-16-2024, 01:27 AM)kenjis Wrote: You passed 5 paramters to request() method, but you must pass 3 parameters.
The third parameter is an array.

PHP Code:
    $response $client->request('GET'$uri ,
                                                [
                                                  'auth' => ['xxx''xxx''basic']
                                                ],
                                              
                                                
[
                                                  'query' =>  [
                                                                'dataDa' => '10/01/2024 00:00:00'
                                                              ]
                                                ],

                                                [
                                                  'query' =>  [
                                                                'dataA' => '15/01/2024 00:00:00'
                                                              ]
                                                ]

                                ); 

Passing array : 

Code:
  public function getTransazionidispenser()
  {
   
    $uri = 'https://www.sinapsiweb.com/API/SinapsiParsedAPI/GetTransazioni';

    $client = \Config\Services::curlrequest();

    $client->request('GET', $uri , ['auth' => ['xxx', 'xxx', 'basic']]);

    $array_query = ['dataDa' => '10/01/2024 00:00:00','dataA' => '15/01/2024 00:00:00'];

    $response = $client->request('GET', $uri, ['query' =>  $array_query ]);
 


    $body = $response->getBody();

    $res = json_decode($body);

    foreach($res as $v){
     
      echo '<pre>';
      print_r($v);
   
    }

  }

Same error
Reply
#17

Why don't you send 'auth'?
I think you cannot access the API without auth credentials.
Reply
#18

(01-16-2024, 01:51 AM)kenjis Wrote: Why don't you send 'auth'?
I think you cannot access the API without auth credentials.

send auth :

Code:
  public function getTransazionidispenser()
  {
   
    $uri = 'https://www.sinapsiweb.com/API/SinapsiParsedAPI/GetTransazioni';


    $client = \Config\Services::curlrequest();


    $response = $client->request('GET', $uri , [
                                                  'auth' => ['xxx', 'xxx', 'basic'],

                                                  'query'=> [
                                                              'dataDa' => '10/01/2024 00:00:00',
                                                              'dataA' => '15/01/2024 00:00:00'

                                                            ]


                                                ]);
 


    $body = $response->getBody();

    $res = json_decode($body);

    foreach($res as $v){
     
      echo '<pre>';
      print_r($v);
   
    }

  }
   

now work !!! Thank you so much !!!
Reply
#19

Good!
If you want to get an error response, add 'http_errors' => false in the array.
https://codeigniter4.github.io/CodeIgnit...ttp-errors
Reply




Theme © iAndrew 2016 - Forum software by © MyBB