Jump to content

how to send HTTP get Request to the webservice end point?


mali

Recommended Posts

Hello,

If i am not posting this question at right location then i apologize for it.

 

My problem is: I need to send HTTP get request to the webservice end point which must include the following http headers:

 

GET / HTTP/1.1

Host: apis.live.net

Accept: application/json

Content-Type: application/json

Authorization: WRAP access_token=AuthToken (here AuthToken is the Access Token String)

 

Note: I am using OAuth for getting an access Token but for getting contents I need to send an HTTP get request.

 

Any kind of help will be appreciated.

Thanks

 

 

Thank you for your suggestion; actually I used curl, but problem is to include the above http headers... which i did nt find through curl; however i tried this approach..

$url = "http://apis.live.net/V4.0/cid-CID/Contacts/AllContacts";

$compURL = http_build_query(array('access_token' => $accessToken));

 

$opts = array('http' => array(

        'method'  => 'GET',

        'header'  => 'Content-type: application/json',

    //'header' => 'Host: apis.live.net',

        'user_agent' => 'Authorization: WRAP',

    'content' => $compURL   

    //'content' => $postdata,

   

    )

);

 

$response = file_get_contents($url, true, $context);

but did nt recieve any response..  how can i use same stuff with curl instead of "file_get_contents()" because i also want to see which URL i am sending.

I also tried curl as following:

$url = "http://apis.live.net/V4.0/cid-CID/Contacts/AllContacts";

 

$session=curl_init($url);

curl_setopt($session, CURLOPT_HEADER, true);

curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

 

$response = curl_exec($session);

 

if(!curl_errno($session))

{

  $info=curl_getinfo($session);

//$info = curl_getinfo($session);

 

echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];

}

 

curl_close($session);

 

But problem is how can i include following HTTP headers by only using curl:

GET / HTTP/1.1

Host: apis.live.net

Accept: application/json

Content-Type: application/json

Authorization: WRAP access_token=AuthToken

 

 

Archived

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

×
×
  • Create New...

Important Information

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.