问题描述
我想发布的信息对我创建和托管的Web项目的API。我不知道确切的格式是HTTP POST请求。每次我尝试,我得到HTTP 400错误与存在无效的动词。
I am trying to post information to an API on a web project that I have created and hosted. I am not sure what the exact format is for the HTTP POST request. Every time I try I get HTTP 400 errors with the message that there is "an invalid verb".
样code:
byte server[] = {"our IP"}
..
..
client(server, 80)
..
..
client.println("POST /Api/AddParking/3");
它连接到没有任何问题提供的IP地址,但我回来在上面提到的HTTP错误code 400,我不知道我是否应该包括我的职务或与内容后,HTTP版本 - 长或任何其他信息。
It connects to the IP address supplied without any problems, but all I get back in the above mentioned HTTP error code 400. I am not sure if I was supposed to include a HTTP version after my POST or and Content-Length or any other information.
推荐答案
原来的问题已经回答了,但只是针对通过谷歌路过的人参考;这里是一个更完整的例子,如何发布数据与一个Arduino web服务器:
The original question is already answered, but just for reference for people passing by via Google; here is a more complete example how to post data to a webserver with an Arduino:
IPAddress server(10,0,0,138);
String PostData = "someDataToPost";
if (client.connect(server, 80)) {
client.println("POST /Api/AddParking/3 HTTP/1.1");
client.println("Host: 10.0.0.138");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(PostData.length());
client.println();
client.println(PostData);
}
这篇关于制作使用Arduino的一个HTTP POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!