Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful client in c

Hi I want to make RESTful call to remote sever. url is http://bulksms.net/API.svc/sms/json/sendmessage?username=newuser&password=newpasswd&msg=test&msisdn=9999999999&tagname=Demo&shortcode=8888&telcoId=5&dnRequired=false The server document says:

Parameters

string username, string password, string msg, string msisdn, string tagname, string shortcode, int telcoId, bool dnRequired

Return Value API will return and object containing three members IsSuccess Message UniqueId

I have made a sample client in c but its not working. below is my code.

#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

int main(int argc, char *argv[])
{
  CURL *curl;
  char url[80];
  CURLcode res;

  strcpy(url,"http://bulksms.net/API.svc/sms/json/sendmessage?username=newuser&password=newpasswd&msg=test&msisdn=9999999999&tagname=Demo&shortcode=8888&telcoId=5&");

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_POST, url);

    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
  return 0;
}

Output :

like image 537
JYOTI RANJAN PANDA Avatar asked Dec 28 '25 10:12

JYOTI RANJAN PANDA


1 Answers

I resolved the problem. Actually in RESTful POST method url and data should be added part by part. below is the successfull client in c for RESTfull POST method.

#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

int main(int argc, char *argv[])
{
  CURL *curl;
  CURLcode res;
  char url[]= "http://bulksms.net/API.svc/sms/json/sendmessage";
  char postData[] = "username=newuser&password=newpasswd&msg=test&msisdn=9999999999&tagname=Demo&shortcode=8888&telcoId=5&dnRequired=false";
  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
  return 0;
}
like image 109
JYOTI RANJAN PANDA Avatar answered Dec 31 '25 01:12

JYOTI RANJAN PANDA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!