mali Posted August 11, 2010 Share Posted August 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/210417-how-to-send-http-get-request-to-the-webservice-end-point/ Share on other sites More sharing options...
Adam Posted August 11, 2010 Share Posted August 11, 2010 Look into cURL. Quote Link to comment https://forums.phpfreaks.com/topic/210417-how-to-send-http-get-request-to-the-webservice-end-point/#findComment-1097967 Share on other sites More sharing options...
mali Posted August 11, 2010 Author Share Posted August 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/210417-how-to-send-http-get-request-to-the-webservice-end-point/#findComment-1097971 Share on other sites More sharing options...
mali Posted August 11, 2010 Author Share Posted August 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/210417-how-to-send-http-get-request-to-the-webservice-end-point/#findComment-1097972 Share on other sites More sharing options...
AbraCadaver Posted August 11, 2010 Share Posted August 11, 2010 Did you try: http://us2.php.net/http_get and then you can use: http://us2.php.net/manual/en/function.http-parse-headers.php and/or: http://us2.php.net/manual/en/function.http-parse-message.php Quote Link to comment https://forums.phpfreaks.com/topic/210417-how-to-send-http-get-request-to-the-webservice-end-point/#findComment-1098123 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.