i try to write a MtGox client using C and libcurl on linux, but i repaet to get this well known error:
according to MtGox' API-reference i use the following code (very ugly, i know):
#include
#include
#include
#include
#include
#include
#include
#include
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:
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