带有HTTP1.1的SQL插入

Sorry for an amateur question but I have no idea why this does not work. I have a "add.php" to connect to the SQL server

<?php
    include("connect.php");

    $link=Connection();

    $ID1=$_POST["ID1"];
    $ID2=$_POST["ID2"];
    $ID3=$_POST["ID3"];
    $ID4=$_POST["ID4"];
    $ID5=$_POST["ID5"];

    $query = "INSERT INTO Battery (ID01, ID02, ID03, ID04, ID05) 
        VALUES ('".$ID1."','".$ID2.",'".$ID3.",'".$ID4."','".$ID5."')"; 

    mysql_query($query,$link);
    mysql_close($link);

    header("Location: index.php");
?>

I use a simple HTTP 1.1 protocols

GET /add.php?ID1=1int&ID2=2char&ID3=3char&ID4=4int&ID5=2015-04-13 01:00:00 HTTP/1.1\myhost
Content-Type: application/x-www-form-urlencoded
Connection:close



The host throw me this error:

+IPD,168:<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>hosting</center>
</body>
</html>

If anyone have any idea for my to try out, I would be grateful! I'm really clueless...

Here the PHP code is handling a POST request while you are making a GET call. Try changing the $_POST to $_GET like below:

<?php
    include("connect.php");

    $link=Connection();

    $ID1=$_GET["ID1"];
    $ID2=$_GET["ID2"];
    $ID3=$_GET["ID3"];
    $ID4=$_GET["ID4"];
    $ID5=$_GET["ID5"];

    $query = "INSERT INTO Battery (ID01, ID02, ID03, ID04, ID05) 
            VALUES ('".$ID1."','".$ID2.",'".$ID3.",'".$ID4."','".$ID5."')"; 

    mysql_query($query,$link);
    mysql_close($link);

    header("Location: index.php");
?>

And if you don't wanna change your PHP code then make a POST request to the file.

EDIT:

Sorry, I just saw that you are using POST request. The Content-Type: application/x-www-form-urlencoded. Still I'll keep the above content.

Please refer to this answer.

Try passing the data through HTTP request through XML, It will be more structured and manageable.

POST Method

The POST method is used when you want to send some data to the server, for example, file update, form data, etc. The following example makes use of POST method to send a form data to the server, which will be processed by a process.cgi and finally a response will be returned:

POST /cgi-bin/process.cgi HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.domain.com/add.php
Content-Type: text/xml; charset=utf-8
Content-Length: <!-- The Content Length -->
Accept-Language: en-us
Accept-Encoding: gzip, deflate <!-- optional -->
Connection: Keep-Alive
<?xml version="1.0" encoding="utf-8"?>
<DATA>    
    <ID>ID01</ID>
    <ID>ID02</ID>
    <ID>ID03</ID>
    <ID>ID04</ID>
    <ID>ID05</ID>
</DATA>

Maybe you need to change the XML as per your need or format of Data.

For more info please refer LinkA, LinkB and LinkC


Hope this helps...