1

As this is my first post on this website, excuse me if I do some mistakes (like wrong title, forgetting something, etc).

I am developing PHP scripts (bots), and I'm using cURL to do this.
So I've coded a lot of things and I was always able to find the solution to my problems myself. Just to tell you that I DID search in MANY places before I write here.

So my problem is that I have to send an AMF request using PHP. I've gathered a lot of informations, tested a lot of codes, but none worked even if I got different results each time.
What I know is the request to send, where to send it, the referer for it, the method (POST/GET, POST in this case) to send it, but there is something I'm doing wrong.
I'll paste one of the hundreds of codes I've tested so that you can see the problem closer.

$url contains the url of the amf gateway
$postfields contains the amf request, I'm not sure if it needs to be placed here but I already tried to add it in the headers array
$referer contains the referer (obviously).

This isn't the WHOLE code but the values you need are already here.

function go_page($url, $postfields = array(), $referer = '')
{
    global $ch;

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    curl_setopt($ch, CURLOPT_REFERER, $referer);

    return curl_exec($ch);
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-amf'));
$postfields = array('\x00\x03\x00\x00\x00\x01\x00\x16\x57\x68\x65\x65\x6c\x53\x65\x72\x76\x69\x63\x65\x2e\x73\x70\x69\x6e\x57\x68\x65\x65\x6c\x00\x02\x2f\x31\x00\x00\x00\x09\x0a\x00\x00\x00\x01\x02\x00\x01\x32');
echo go_page($url, $postfields, $referer);

This is the output : HTTP/1.1 100 Continue HTTP/1.1 200 OK Date: Sat, 12 Sep 2015 18:22:31 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.4.28 X-Cobalt: loaded Content-Length: 0 Connection: close Content-Type: text/html; charset=UTF-8.

Thanks in advance for your help...

Edit : I've already tried putting the request in the header array.

Neox
  • 279
  • 3
  • 13
  • maybe $postfields must be a string? – Maxim Dvorkin Sep 12 '15 at 18:58
  • No, $postfields is an array, I already used this a lot of times. The problem isn't there (I wrote around 1k lines and I use $postfields a lot of times, it works, gives me the expected results, no warnings no notices) – Neox Sep 12 '15 at 20:25
  • I mean try to send post data like string(my bad english) :) http://stackoverflow.com/a/7422395/4189313 – Maxim Dvorkin Sep 12 '15 at 20:36
  • If value(CURLOPT_POSTFIELDS) is an array, the Content-Type header will be set to multipart/form-data. From http://php.net/manual/en/function.curl-setopt.php p.s. I have not tested when the specified header – Maxim Dvorkin Sep 12 '15 at 20:44
  • Ah you mean send the header as string, I saw this post before (I really searched a lot), but this tells me 400 Bad request (something like that, forgot) – Neox Sep 12 '15 at 20:44
  • $postfields is always an array, it's $options in the first link you gave me – Neox Sep 12 '15 at 20:50
  • Don't know if this helps, but Amfphp reads incoming raw data, and it's a string, not an array. So try looking at posting raw data with curl. Like this for example:http://stackoverflow.com/questions/871431/raw-post-using-curl-in-php – Ariel Sommeria-Klein Sep 16 '15 at 07:58
  • Ok so I have replaced the content of $postfields with this : `$postfields = '\x00\x03\x00\x00\x00\x01\x00\x16\x57\x68\x65\x65\x6c\x53\x65\x72\x76\x69\x63\x65\x2e\x73\x70\x69\x6e\x57\x68\x65\x65\x6c\x00\x02\x2f\x31\x00\x00\x00\x09\x0a\x00\x00\x00\x01\x02\x00\x01\x32';` but it still tells me `HTTP/1.1 200 OK Date: Wed, 16 Sep 2015 21:38:47 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.4.28 X-Cobalt: loaded Content-Length: 0 Connection: close Content-Type: text/html; charset=UTF-8`. – Neox Sep 16 '15 at 21:39

0 Answers0