View Full Version : API GET requests.
i know this might sound really simple, but what would be the best way to retrieve information by doing a get request in php, like for example the end of the url would be something like
?account=joe&pass=xxx&action=showObjectReport
I'm pretty sure it would be using cURL, not sure how to use that though.
Cheers for the help, never really used an API before :/
Joe
Agnostic Bear
28-01-2010, 11:04 PM
i know this might sound really simple, but what would be the best way to retrieve information by doing a get request in php, like for example the end of the url would be something like
?account=joe&pass=xxx&action=showObjectReport
I'm pretty sure it would be using cURL, not sure how to use that though.
Cheers for the help, never really used an API before :/
Joe
What on earth are you on about, what API and what are you trying to do?
Blinger1
28-01-2010, 11:07 PM
And why would the pass be in the URL!? That's like giving the key to a prisoner and asking him not to let himself out!
Reading that back, it doesn't make sense at all does it. Basically i'm trying to connect to tomtom workfleet to retrieve the location of a vehicle. It uses either HTTP requests like I said about with the url, or SOAP requests which i dont have a clue about.
I've just seen this on a website, could I use that same technique to retrieve the data?
$url = "http://piwik.org/demo/";
$url .= "?module=API&method=Referers.getKeywords";
$url .= "&idSite=1&period=month&date=yesterday";
$url .= "&format=PHP&filter_limit=20";
$url .= "&token_auth=$token_auth";
$fetched = file_get_contents($url);
$content = unserialize($fetched);
Also, this is direct from tomtom, but is in ASP, i'm essentially trying to complete the same task in PHP.
url = "https://new.webfleet.de/extern?"
url = url + "lang=" + Request.form("lang")
url = url + "&account=" + Request.form("account")
url = url + "&username=" + Request.form("username")
url = url + "&password=" + Request.form("password")
url = url + "&action=showObjectReportExtern"
Set Req = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
Req.Open "GET", url
Req.Send
Response.Write Req.ResponseText
Set Req = nothing
Invent
29-01-2010, 05:06 PM
Also, this is direct from tomtom, but is in ASP, i'm essentially trying to complete the same task in PHP.
url = "https://new.webfleet.de/extern?"
url = url + "lang=" + Request.form("lang")
url = url + "&account=" + Request.form("account")
url = url + "&username=" + Request.form("username")
url = url + "&password=" + Request.form("password")
url = url + "&action=showObjectReportExtern"
Set Req = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
Req.Open "GET", url
Req.Send
Response.Write Req.ResponseText
Set Req = nothing
Something like this should work if you want to use cURL.
<?php
$parameters = array(
'lang' => 'Language',
'account' => 'Account',
'Password' => 'Password',
'action' => 'showObjectReportExtern',
);
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, 'https://new.webfleet.de/extern?' . http_build_query( $parameters ) );
curl_setopt( $curl, CURLOPT_HEADER, false );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false );
$response = curl_exec( $curl );
curl_close( $curl );
Thanks for that Invent! :)
Shall test it out when I can :)
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.