Hi, I've been trying for the last week to figure this out, but no luck at all. I've posted my code and output below. Code: PHP: <?php // Sends CURL Request function createThread($forum, $title, $body) { $ch = curl_init(); $data = array( 'oauth_token' => 'REMOVED', 'forum_id' => $forum, 'thread_title' => $title, 'post_body' => $body ); curl_setopt($ch, CURLOPT_URL, "http://themineville.com/api/threads"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $result = curl_exec($ch); $info = curl_getinfo($ch); var_dump($info); curl_close($ch); return $result; } // Builds thread body function doBan($username,$sender,$reason) { $date = date('H:i @ d/m/Y'); $forum = 14; $body = "This is an automated ban report! Originally sent in by [B]@".$sender."[/B]\n\n"; $body .= "[B]Username:[/B] ".$username."\n[B]Time & Date:[/B] ".$date."\n"; $body .= "[B]Temporary:[/B] YES/NO [COLOR=#ff0000]!TODO[/COLOR]\n"; $body .= "[B]Reason:[/B] ".$reason."\n"; $body .= "[B]Proof:[/B] [COLOR=#ff0000]!TODO[/COLOR]"; $body .="\n\n@".$sender." Please update this and then remove these automated message."; $send = createThread($forum, $username, $body); } $return = doBan("Sekonda","Sekonda","Test API"); var_dump($return); ?> Output: Edit: When I run the curl command via Terminal I get Empty Response from Server
You need to return the $send variable in doBan method to get server response for the request. What is your curl command btw?
The curl command is the equivalent to below, where BLAH is $data Code: curl -XPOST http://themineville.com/api/threads -d 'BLAH' I added the return in, but it doesn't show anything because the createThread returns null
Thanks for sending me the token. However, it looks like your server blocked POST requests targetting /api/, can you check for that? It can be Apache or firewall (iptables)? That's why you get empty response from server.
Sekonda @xfrocks It works if I try to post from Postman, but not using curl. Shall speak to the host now though.
xfrocks @Sekonda Very likely a firewall issue. Probably mod_security or similar. I'll try again when you sort that out okie?
Hi @xfrocks I spoke to the host, they said nothing is blocked at their end and tested a POST curl request on the same site and it worked fine.
You have just enabled CloudFlare, right? Because executing `curl -XPOST http://themineville.com/` is now returning CloudFlare error "520: Web server is returning an unknown error"
It was enabled last night, I disabled it before to see if it was that blocking it. However there is a rule for /api/* for it to bypass the cache.
Executing `curl -XPOST http://themineville.com/api/threads` yelded the same response. Definitely something is blocking it (from the server, not CF)... I tried different user agent with curl but that doesn't work.
For our testing purpose, there are many tools to use. However, for PHP scripts, curl library is probably the best of its kind: easy to use, extremely powerful... Behind the scene, curl command and curl library run the same code so you will not be able to run your script.