Arduino以太网盾 - GET - WebClient - 400错误请求

时间:2015-10-13 10:48:49

标签: arduino

我在Arduino中使用PHP中的GET发送数据时遇到问题。我从Arduino IDE打开WebClient代码,只需更改char server []并获取内容。

我使用该代码将记录添加到我的MySQL数据库中。

http://cineksuw.hol.es/mysql.php?d=10&t=20&h=30&p=40

你可以看到它有效,所以我尝试使用arduino:

char server[] = "http://cineksuw.hol.es";

  if (client.connect(server, 80)) {
  Serial.println("connected");
  // Make a HTTP request:
  client.println("GET /mysql.php?d=1&t=5&h=1&p=4 HTTP/1.1");
  client.println("Host: http://cineksuw.hol.es");
  client.println("Connection: close");
  client.println();}

但是这段代码不起作用,我明白了:

    connecting...
connected
HTTP/1.1 400 Bad Request
Server: nginx/1.9.3
Date: Tue, 13 Oct 2015 10:42:57 GMT
Content-Type: text/html
Content-Length: 172
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.9.3</center>
</body>
</html>

disconnecting.

有什么问题?谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

client.connectHost标题中,您应该只使用域名,而不是HTTP地址。即:

char server[] = "cineksuw.hol.es";
if (client.connect(server, 80)) {
...

client.println("Host: cineksuw.hol.es");
相关问题