I have following command in cURL, this works fine in terminal.
curl --insecure -X POST --data "username=testuser&password=12345" https://m360-prototype.herokuapp.com/sessions.json
This json api sends a few parameters like these-- "status":{"code":200,"message":"OK"}
Now i want my c++ program to execute it. I have set up and used cURL before for ftp upload and download from ftp examples. But i did not find any example to do this.
I want to know how can i pass username and password parameters to the json api, and get response from it.
Here is what i have tried in some code I found on web, it didnt work.
struct curl_slist *headers=NULL; // init to NULL is important
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "charsets: utf-8");
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_URL, "https://m360-prototype.herokuapp.com/sessions.json");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "username=testuser&password=12345");
curl_easy_setopt(curl, CURLOPT_HTTPGET,1);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
if(CURLE_OK == res) {
char *ct;
/* ask for the content-type */
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
if((CURLE_OK == res) && ct)
printf("We received Content-Type: %s\n", ct);
}
}
How do i get response from the web? i know it will be in the form of strings, and i am capable enough to parse it.
I am looking up all the params (--insecure, -X, POST, --data)passed to the curl command executed on terminal, so as to get little idea about what i have to do.
I am a graphics programmer :) not so good with web services. I'd appreciate any help.