Bitcoin Forum
August 20, 2019, 09:49:02 PM *
News: Latest Bitcoin Core release: 0.18.0 [Torrent] (New!)
   Home   Help Search Login Register More  
Pages: [1]
Author Topic: MtGox-client using C and libcurl  (Read 1257 times)
Sr. Member
Offline Offline

Activity: 316
Merit: 250

View Profile
July 13, 2011, 02:54:35 PM


i try to write a MtGox client using C and libcurl on linux, but i repaet to get this well known error:

{"error":"Must be logged in"}

according to MtGox' API-reference i use the following code (very ugly, i know):

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <unistd.h>

#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

CURL *csock;
char buffer[100000];
char *post_data;
char *user, *pass;
CURLcode res;

size_t write_data(void *ptr, size_t size, size_t nmemb, char *buf) {
    long i, tmp;


    for(i=0; i<(nmemb*size); i++) {

    return nmemb*size;

int main()

   printf("Please enter username: ");
   user=curl_easy_escape(NULL, user, 0);

   pass=getpass("Please enter password (will be hidden): ");
   pass=curl_easy_escape(NULL, pass, 0);

   csock = curl_easy_init();
   curl_easy_setopt(csock, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1");
   curl_easy_setopt(csock, CURLOPT_NOSIGNAL, 1);
   curl_easy_setopt(csock, CURLOPT_WRITEFUNCTION, write_data);
   curl_easy_setopt(csock, CURLOPT_WRITEDATA, &buffer);
   curl_easy_setopt(csock, CURLOPT_URL, "");
   curl_easy_setopt(csock, CURLOPT_REFERER, "");
   sprintf(post_data, "name=%s&pass=%s", user, pass);
   curl_easy_setopt(csock, CURLOPT_POST, 1);
   curl_easy_setopt(csock, CURLOPT_POSTFIELDS, (void*)&post_data);
   curl_easy_setopt(csock, CURLOPT_USE_SSL, CURLUSESSL_NONE);
   //curl_easy_setopt(csock, CURLOPT_POSTFIELDSIZE, strlen(post_data));

   res = curl_easy_perform(csock);

      printf("Error: %s\n", curl_easy_strerror(res));
      printf("Output: %s\n", buffer);


   return 0;

i know that others got working code for curl in a command-line, for example this one:

curl -v -k --referer --data "name=XXX&pass=YYY" -H "Accept: application/json"

my problem is that i am somehow not able to rebuild this command in my c-code.

i hope someone can help me.


Pages: [1]
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!