mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-04 15:24:12 +01:00
Merge pull request #2170 from arduino/ide-1.5.x-httpclient-post
Added POST to HttpClient
This commit is contained in:
commit
641ea440ff
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2013 Arduino LLC. All right reserved.
|
Copyright (c) 2013-2014 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
@ -28,6 +28,7 @@ unsigned int HttpClient::get(String &url) {
|
|||||||
if (insecure) {
|
if (insecure) {
|
||||||
addParameter("-k");
|
addParameter("-k");
|
||||||
}
|
}
|
||||||
|
addHeader();
|
||||||
addParameter(url);
|
addParameter(url);
|
||||||
return run();
|
return run();
|
||||||
}
|
}
|
||||||
@ -37,6 +38,7 @@ unsigned int HttpClient::get(const char *url) {
|
|||||||
if (insecure) {
|
if (insecure) {
|
||||||
addParameter("-k");
|
addParameter("-k");
|
||||||
}
|
}
|
||||||
|
addHeader();
|
||||||
addParameter(url);
|
addParameter(url);
|
||||||
return run();
|
return run();
|
||||||
}
|
}
|
||||||
@ -46,6 +48,7 @@ void HttpClient::getAsynchronously(String &url) {
|
|||||||
if (insecure) {
|
if (insecure) {
|
||||||
addParameter("-k");
|
addParameter("-k");
|
||||||
}
|
}
|
||||||
|
addHeader();
|
||||||
addParameter(url);
|
addParameter(url);
|
||||||
runAsynchronously();
|
runAsynchronously();
|
||||||
}
|
}
|
||||||
@ -55,6 +58,43 @@ void HttpClient::getAsynchronously(const char *url) {
|
|||||||
if (insecure) {
|
if (insecure) {
|
||||||
addParameter("-k");
|
addParameter("-k");
|
||||||
}
|
}
|
||||||
|
addHeader();
|
||||||
|
addParameter(url);
|
||||||
|
runAsynchronously();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int HttpClient::post(String &url, String &data) {
|
||||||
|
return post(url.c_str(), data.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int HttpClient::post(const char *url, const char *data) {
|
||||||
|
begin("curl");
|
||||||
|
if (insecure) {
|
||||||
|
addParameter("-k");
|
||||||
|
}
|
||||||
|
addParameter("--request");
|
||||||
|
addParameter("POST");
|
||||||
|
addParameter("--data");
|
||||||
|
addParameter(data);
|
||||||
|
addHeader();
|
||||||
|
addParameter(url);
|
||||||
|
return run();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpClient::postAsynchronously(String &url, String &data) {
|
||||||
|
postAsynchronously(url.c_str(), data.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpClient::postAsynchronously(const char *url, const char *data) {
|
||||||
|
begin("curl");
|
||||||
|
if (insecure) {
|
||||||
|
addParameter("-k");
|
||||||
|
}
|
||||||
|
addParameter("--request");
|
||||||
|
addParameter("POST");
|
||||||
|
addParameter("--data");
|
||||||
|
addParameter(data);
|
||||||
|
addHeader();
|
||||||
addParameter(url);
|
addParameter(url);
|
||||||
runAsynchronously();
|
runAsynchronously();
|
||||||
}
|
}
|
||||||
@ -75,3 +115,18 @@ void HttpClient::checkSSL() {
|
|||||||
insecure = false;
|
insecure = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HttpClient::setHeader(String &header) {
|
||||||
|
this->header = header;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpClient::setHeader(const char * header) {
|
||||||
|
this->header = String(header);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpClient::addHeader() {
|
||||||
|
if (header.length() > 0) {
|
||||||
|
addParameter("--header");
|
||||||
|
addParameter(header);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2013 Arduino LLC. All right reserved.
|
Copyright (c) 2013-2014 Arduino LLC. All right reserved.
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
@ -29,6 +29,12 @@ class HttpClient : public Process {
|
|||||||
unsigned int get(const char * url);
|
unsigned int get(const char * url);
|
||||||
void getAsynchronously(String &url);
|
void getAsynchronously(String &url);
|
||||||
void getAsynchronously(const char * 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);
|
||||||
|
void setHeader(String &header);
|
||||||
|
void setHeader(const char * header);
|
||||||
boolean ready();
|
boolean ready();
|
||||||
unsigned int getResult();
|
unsigned int getResult();
|
||||||
void noCheckSSL();
|
void noCheckSSL();
|
||||||
@ -37,6 +43,9 @@ class HttpClient : public Process {
|
|||||||
private:
|
private:
|
||||||
boolean insecure;
|
boolean insecure;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void addHeader();
|
||||||
|
String header;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HTTPCLIENT_H_ */
|
#endif /* HTTPCLIENT_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user