[英]How to send data(String) from HTTP client to server
I've got a simple server, and I need that server to get message from client via http the code of client is我有一个简单的服务器,我需要该服务器通过 http 从客户端获取消息,客户端代码是
import requests
r = requests.post('http://192.168.0.100:7777',data="Hello")
print(r.text)
My server doesn't catch anything.我的服务器没有捕捉到任何东西。 But I'm quite sure they are connected since the text from the server is being displayed in the console但我很确定它们已连接,因为来自服务器的文本显示在控制台中
Server code服务器代码
int httpCode = http.GET();
if(httpCode>=0){
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
}
Are you sure that it's not a server issue?确定不是服务器问题? Try printing r.status_code.尝试打印 r.status_code。
Also, generally you'll want to send the data in a json object.此外,通常您会希望在 json 对象中发送数据。
import json
import requests
data = json.dumps({'message': 'hello'})
request = requests.post('http://192.168.0.100:7777',data=data)
print(request.status_code)
print(request.text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.