1

Arduino YUN用于IoT项目。

我有一个需要标头和正文的 Web 服务,我想从arduino.

默认HttpClient库支持 put、get 和 delete 方法,但不支持 post 方法。

任何建议都会很棒。谢谢。

4

2 回答 2

0

也许您有旧版本的 Bridge 库。我在 HttpClient.h 中看到的代码支持 POST(版本 1.6.3):

unsigned int get(String &url);
unsigned int get(const char * url);
void getAsynchronously(String &url);
void getAsynchronously(const char * url);
unsigned int post(String &url, String &data);
unsigned int post(const char * url, const char * data);
void postAsynchronously(String &url, String &data);
void postAsynchronously(const char * url, const char * data);
unsigned int patch(String &url, String &data);
unsigned int patch(const char * url, const char * data);
void patchAsynchronously(String &url, String &data);
void patchAsynchronously(const char * url, const char * data);
unsigned int put(String &url, String &data);
unsigned int put(const char * url, const char * data);
void putAsynchronously(String &url, String &data);
void putAsynchronously(const char * url, const char * data);
void setHeader(String &header);
void setHeader(const char * header);
boolean ready();
unsigned int getResult();
void noCheckSSL();
void checkSSL();
于 2017-09-15T18:51:45.963 回答
0

You can use the Process class to send the POST via curl (which is a part of OpenWRT on Arduino YÚN).

Example from http://starter-kit.nettigo.eu/2014/arduino-yun-sending-data-thingspeak-post/:

void postToThingSpeak(String key, float value[]) {
  Process p;
  String cmd = "curl --data \"key="+key;
  for (int i=0;i<ARRAY_SIZE;i++) {
    cmd = cmd + "&field"+ (i+1) + "=" + value[i];
  }
  cmd = cmd + "\" http://api.thingspeak.com/update";
  p.runShellCommand(cmd);
  Console.println(cmd);
  p.close();
}
于 2016-07-24T19:32:11.703 回答