0

I have little function for get content result with cURL; When i tried without POST, all working good, but with POST enabled, the result is null.

This code don't work:

function getAPI($url){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST, true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,'shard=Apex');     
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3");
    $result = curl_exec($ch);
    return $result; 
    curl_close($ch);
}   

This code work but the request is not passed like a POST:

function getAPI($url){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    //curl_setopt($ch,CURLOPT_POST, true);
    //curl_setopt($ch,CURLOPT_POSTFIELDS,'shard=Apex');   
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3");
    $result = curl_exec($ch);
    return $result; 
    curl_close($ch);
}   

I call this function with this command:

echo getAPI('http://world.needforspeed.com/SpeedAPI/ws/cmsbridge/news/rss/fr_FR');

You can also try with this URL

http://world.needforspeed.com/SpeedAPI/ws/game/nfsw/driver/levelkro/profile

This URL work only if shard=Apex (default shard=CHICANE for CHHICANE Server, but my profil is only available on Apex Server)

2
  • There is a lot left to the imagination on this one. Can you provide more details about what you are posting? When I post to this via command line I get <?xml version="1.0" encoding="UTF-8"?> <null/>. So is this API meant to be posted to? Commented Aug 10, 2012 at 21:50
  • Have you tried passing as an array for you CURL_POSTFIELDS? Commented Aug 10, 2012 at 22:15

2 Answers 2

2

According to the SpeedAPI-manual (a simple Google-search) it would seem that the given URL does not accept the "shard" POST-parameter...

SpeedAPI Manual for Get News RSS Feed

You can however use a GET-request and use a shard-parameter where applicable according to the manual.

For example: http://world.needforspeed.com/SpeedAPI/ws/game/nfsw/driver/DRIVER_NAME/profile?shard=APEX (make sure you enter the shard-parameter in capitals)

Sign up to request clarification or add additional context in comments.

8 Comments

You can view the entire SpeedAPI manual @ http://world.needforspeed.com/SpeedAPI/doc/ You can only use the parameters listed under "Input parameters". Everything else should be passed using the URI parameters. (Basically: don't use POST...)
I know the API, with socket I can make same request for GET and POST without problem (but it's long), just with cURL on POST I give an error.
Does it work when you use echo getAPI('http://world.needforspeed.com/SpeedAPI/ws/game/nfsw/driver/DRIVER_NAME/profile?shard=Apex'); (with GET, not POST). Substitute DRIVER_NAME with an actual name or you'll get the DRIVERNAME_NO_MATCH-error.
Try this url: world.needforspeed.com/SpeedAPI/ws/game/nfsw/driver/levelkro/… only work if shard=Apex because the profile is not on Chicane
Please try to refrain from "LMGTFY"-style answers. Either provide the answer or not, "simply google it" is beside the point.
|
0

Have you tried passing the parameter as an array like this instead:

curl_setopt($ch,CURLOPT_POSTFIELDS,array('shard' => 'Apex'));  

1 Comment

no sorry, return: <?xml version="1.0" encoding="UTF-8"?> <null/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.