Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Cooler`s simple Rest test... ( http://en.wikipedia.org/wiki/Representational_state_transfer )
- i use this URL
- http://httpbin.org/
- to test with libcurl in C...
- i have other purposes to use...
- other ways to test
- test client:
- http://resttesttest.com/
- with rails:
- $ rails new restweb && cd restweb
- $ rails generate scaffold post title:string body:string
- $ rails server
- goto http://127.0.0.1:3000/posts (.json)
- to run: gcc -o code code.c -l curl; ./code
- contact: c00f3r [at] gmail [dot] com
- */
- #include <stdio.h>
- #include <curl/curl.h>
- int main(void)
- {
- CURL *curl;
- CURLcode res;
- curl_global_init(CURL_GLOBAL_ALL);
- curl = curl_easy_init();
- if(curl)
- {
- char* jsonObj = "{ \"name\" : \" coolerudos\" , \"pass\" : \"milk666\" }";
- struct curl_slist *headers = NULL;
- curl_slist_append(headers, "Accept: application/json");
- curl_slist_append(headers, "Content-Type: application/json");
- curl_slist_append(headers, "charsets: utf-8"); // maybe not cool use utf8...
- curl_easy_setopt(curl, CURLOPT_URL, "http://httpbin.org/put");
- curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonObj);
- curl_easy_setopt(curl, CURLOPT_USERAGENT, "hellblazer/0.666");
- res = curl_easy_perform(curl);
- curl_easy_cleanup(curl);
- }
- curl_global_cleanup();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment