抱歉提出了一个业余问题,但我不知道为什么这不起作用。 我有一个“add.php”来连接到 SQL 服务器
<?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");
?>
我使用简单的 HTTP 1.1 协议
GET /add.php?ID1=1int&ID2=2char&ID3=3char&ID4=4int&ID5=2015-04-13 01:00:00 HTTP/1.1\r\myhost\r\nContent-Type: application/x-www-form-urlencoded\r\nConnection:close\r\n\r\n\r\n
主机向我抛出这个错误:
+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>
如果有人有任何想法让我尝试,我将不胜感激!我真的很无知...
请参考这个答案。
尝试通过HTTP请求通过XML传递数据,会更加结构化和可管理。
POST 方法
POST 方法用于向服务器发送一些数据,例如文件更新、表单数据等。下面的示例利用 POST 方法向服务器发送表单数据,服务器将处理这些数据一个process.cgi,最后将返回一个响应:
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>
也许您需要根据您的需要或数据格式更改 XML。