Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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: %sn", ct);
- }
- }
- std::string data = "username=testuser&password=12345";
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.length());
- curl_easy_setopt(curl, CURLOPT_POST, 1);
- std::string data = "{"username":"testuser","password":"12345"}";
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); // for --insecure option
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.length());
- curl_easy_setopt(curl, CURLOPT_POST, 1);
- CURLcode ret;
- CURL *hnd;
- struct curl_slist *slist1;
- std::string jsonstr = "{"username":"bob","password":"12345"}";
- slist1 = NULL;
- slist1 = curl_slist_append(slist1, "Content-Type: application/json");
- hnd = curl_easy_init();
- curl_easy_setopt(hnd, CURLOPT_URL, "http://u/r/l");
- curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
- curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, jsonstr.c_str());
- curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.38.0");
- curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);
- curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
- curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
- curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
- ret = curl_easy_perform(hnd);
- curl_easy_cleanup(hnd);
- hnd = NULL;
- curl_slist_free_all(slist1);
- slist1 = NULL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement