less duplication
This commit is contained in:
parent
93b7670bbe
commit
ba90623c3a
1 changed files with 15 additions and 3 deletions
18
src/main.cpp
18
src/main.cpp
|
@ -172,7 +172,7 @@ void handleData1Interrupt() {
|
|||
|
||||
|
||||
// Function to send the authentication request to the endpoint
|
||||
std::pair<String, int> sendTinance2HttpRequest(String url, String payload) {
|
||||
std::pair<String, int> sendTinance2HttpRequest(String url, String method, String payload) {
|
||||
HTTPClient http;
|
||||
|
||||
if (!http.begin(url)) {
|
||||
|
@ -192,7 +192,19 @@ void handleData1Interrupt() {
|
|||
http.setTimeout(5000);
|
||||
|
||||
// Send the POST request
|
||||
int httpResponseCode = http.POST(payload);
|
||||
int httpResponseCode;
|
||||
if (method == "POST") {
|
||||
httpResponseCode = http.POST(payload);
|
||||
} else if (method == "GET") {
|
||||
httpResponseCode = http.GET();
|
||||
} else {
|
||||
// Handle invalid method
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.println("Invalid HTTP method");
|
||||
#endif
|
||||
http.end();
|
||||
return std::make_pair("", -1);
|
||||
}
|
||||
|
||||
if (httpResponseCode <= 0) {
|
||||
#ifdef SERIAL_DEBUG
|
||||
|
@ -226,7 +238,7 @@ void handleData1Interrupt() {
|
|||
// Create the JSON payload
|
||||
String payload = "{\"full_card_id\":\"" + String(fullCardID) + "\"}";
|
||||
// Send the HTTP request and get the response
|
||||
std::pair<String, int> responsePair = sendTinance2HttpRequest(url, payload);
|
||||
std::pair<String, int> responsePair = sendTinance2HttpRequest(url, "POST", payload);
|
||||
String response = responsePair.first;
|
||||
int httpResponseCode = responsePair.second;
|
||||
|
||||
|
|
Loading…
Reference in a new issue