Jump to content

Making external request


Tom S.

Recommended Posts

Posted

I'm trying to make an external request using

\IPS\Http\Url::external($somepath)->request()->setHeaders( array('Content-Type' => 'application/json') )->post( array());

So I can set the body and the headers. But How do I set the authorization?  So either CURLOPT_USERPWD or a token?

Posted

I use in a resource:

		$result = \IPS\Http\Url::external( "api.openweathermap.org/data/2.5/weather?q=Brasilia,br?&lang=pt&units=metric&appid=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" )->request( 20 )->get();
		$data = json_decode( $result );

 

Posted
$response = \IPS\Http\Url::external( "url" )
	->request()
	->setHeaders( array( 'Content-type' => 'application/json' ) )
	->login( 'username', 'password' )
	->post( array() )
	->decodeJson();
$response = \IPS\Http\Url::external( "url" )
	->request()
	->setHeaders( array( 'Authorization' => "Bearer {$this->token['access_token']}", 'Content-type' => 'application/json' ) )
	->post( array() )
	->decodeJson();

I would really suggest going over our developer documentation - it's all covered there. 🙂

 

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...