Oyster Harvest Area Closure Analysis 0.1
Prediction and analysis of NSW oyster harvest area closures.
Loading...
Searching...
No Matches
http.h File Reference
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "utils.h"
Include dependency graph for http.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

CURLcode HttpRequest (cJSON **response, const char *URL, struct curl_slist *headers, int8_t post, const char *body)
 HTTP GET & POST request using cURL. More...
 

Function Documentation

◆ HttpRequest()

CURLcode HttpRequest ( cJSON **  response,
const char *  URL,
struct curl_slist *  headers,
int8_t  post,
const char *  body 
)

HTTP GET & POST request using cURL.

Basic HTTP request using CURL.

Most initialisation is done outside of this function. This function just handles the HTTP request and puts the data inside a provided cJSON object. Note this function has a memory leak on a Mac M1 -> (curl_easy_perform()) has 13 leaks, totalling 496 bytes per call.

const char *URL = "https://www.example.com";
// Create some headers (more may be needed depending on application)
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
// Create a cJSON object to hold the response
cJSON *response = NULL;
CURLcode result = HttpRequest(&response, URL, headers, 0, NULL);
// Free memory
curl_slist_free_all(headers);
cJSON_Delete(response);
CURLcode HttpRequest(cJSON **response, const char *URL, struct curl_slist *headers, int8_t post, const char *body)
HTTP GET & POST request using cURL.
Definition: http.c:34
Parameters
responseThe cJSON response to populate with JSON.
URLThe request URL.
headersHeaders to include in request.
postInterger flag to request POST request (set to 1).
bodyPOST request body.
Returns
Status code representing the response status.