Bitcoin Forum
December 05, 2016, 08:58:07 PM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: MtGox-client using C and libcurl  (Read 1170 times)
gimme_bottles
Sr. Member
****
Offline Offline

Activity: 314



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

hi,

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

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

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

Code:
#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;

    tmp=strlen(buf);

    for(i=0; i<(nmemb*size); i++) {
        *(buf+(i+tmp))=*((char*)ptr+i);
    }

    return nmemb*size;
}

int main()
{
   user=malloc(100);
   pass=malloc(100);
   post_data=malloc(1000);


   printf("Please enter username: ");
   gets(user);
   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, "https://mtgox.com/code/getFunds.php");
   curl_easy_setopt(csock, CURLOPT_REFERER, "https://mtgox.com");
   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);


   if(res!=CURLE_OK)
      printf("Error: %s\n", curl_easy_strerror(res));
   else
      printf("Output: %s\n", buffer);


   free(user);
   free(pass);
   free(post_data);
   curl_free(csock);

   return 0;
}



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

Code:
curl -v -k --referer https://mtgox.com --data "name=XXX&pass=YYY" -H "Accept: application/json" https://mtgox.com/code/getFunds.php

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


i hope someone can help me.

regards,


gimme_bottles

1Gk194CHEgFPbh8gEM7agMNRXeWkfw2Fv7
Pages: [1]
  Print  
 
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!