2015-10-13 75 views
1

我在使用PHP在Arduino中使用GET發送數據時遇到問題。我從Arduino IDE打開WebClient代碼,只需更改char server []並獲取東西。Arduino以太網盾 - GET - WebClient - 400錯誤請求

我使用該代碼將記錄添加到我的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. 

是什麼問題?感謝幫助。

回答

0

都在client.connectHost標題你應該只使用域名,而不是一個HTTP地址。即:

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

client.println("Host: cineksuw.hol.es"); 
+1

謝謝,我改變這種狀況,但仍是問題。現在沒有關係。 '連接... 連接失敗 斷開連接。 ' 但是,當我再次將'char server'更改爲google.com時,它連接時沒有問題。我的網站是好的,工作。 – MarcinAWK