What's the difference between POST and raw POST in PHP at all?

后端 未结 4 1409
情话喂你
情话喂你 2020-12-05 09:13

I have this question after reading the answer here, what\'s the difference at all?

Is it possible to submit raw POST with html ?

4条回答
  •  情书的邮戳
    2020-12-05 09:40

    $HTTP_RAW_POST_DATA will contain something like:

    beans=cheese&spam=eggs&one=two
    

    PHP splits this up for you, and shoves it in the $_POST array. Naively, it does something like this:

    $parts = explode('&', $HTTP_RAW_POST_DATA);
    foreach ( $parts as $part ) {
        list($key, $value) = explode('=', $part, 2);
        $_POST[$key] = $value;
    }
    

    Using JavaScript, which can be embedded into HTML, you can POST anything you like with AJAX. Something like this:

    var req = new XMLHttpRequest();
    req.open('POST', 'http://www.example.com/my_url' true);
    req.send('any data you want');
    

    will allow you to POST arbitrary things to the web server.

提交回复
热议问题