curl-library
Re: Login paypal
Date: Wed, 07 Nov 2007 15:24:25 +0100
Hey,
thanks for the snippet but I need HTTPS.
Isn't your example just HTTP?
New question:
How can I extract the server cert and save it locally?
Michael
antel schrieb:
> Michael Hecker ha scritto:
>> Hey,
>> I would like to use curl to login on paypal.com!
>>
>> I used curl successfully to get/post data via http but I've got my
>> problems with https.
>>
>> Would be great, if someone could give me a short snippet on POST via
>> https.
>>
>> Thank you,
>> Michael
>>
>> P.S.: I'm using VC++ under WinXP
>>
> Snippet for sending sms from jajah.com, comments are in italian, taked
>> from a forum, it's easy to understand.
> I want to give you tips, take http headers and get all things firefox
> download in each page, 1/when you enter in paypal 2/when you log in
> 3/main page /etc, results should be like this:
>
> #request# GET http://www.yahoo.it/
> GET /
> #request# GET http://it.yahoo.com/
> #redirect# GET /
> #request# GET
> http://row.bc.yahoo.com/b?P=GoLlYNkMAwtFbx5vR%2fX%3d1187690071%2fE%3d97473701%2fR%3dithmpg%2fK%3d5%fV%3d2.1%2fW%3dR%2fY%3IT%2fF%339109684%2f%3d-1%2fS%3d1%2fJ%3d1500CD9&U=128b48k%2fN%3djXFDNkBSY-%2fC%3d-1%2fD3dTEAR2fB%3d-1
>
> #request# GE
> http://row.bc.yahoo.com/b?P=GoLlYNkMAwtFbx5vR&T=13t127qhr%2fX%3d1187690071%2fE%3d97473701%2fR%3dithmpg%2fK%3d5%2fV%3d.1%2fW%3dHR%2fY%3dIT%2f%3d980671666%2fQ%3-1fS%3d1%2fJ%d15030D9&U=13kuqrb06%2N%3dkHrDkMBSY-%2fC%3d200094790.201406.2026914.20902440%2fD%3dPL%2f3d20633911
>
> #request# GET http://l.yimg.com/eur.yimg.com/i/it/hp/itie.gif
> #request# GET http://us.i1.yimg.com/us.yimg.com/i/ww/answers.gif
> #request# GET http://l.yimg.com/eur.yimg.com/i/it/hp/sarko5.jpg
> #request# GET http://eur.i1.yimg.com/eur.yimg.com/i/it/we/thund2.jpg
> #request# GET http://l.yimg.com/eur.yimg.com/i/it/hp/cruis6.jpg
> #request# GET http://l.yimg.com/eur.yimg.com/i/it/hp/famig2.jpg
> [CUT]
>
> You should make everything like it comes from ie, that's hard work
> otherwise ur account get limited, paypal is a multinational and will
> not make life easier to script kiddies, like cj.com or others they've
> professional protections against this, even with all this things
> script will suffer about no javascript and no activex, I don't know if
> paypal can detect javascript/activex in a hidden way, or a method to
> make webservers think you have javascript/activex using a script, get
> a look at http://gemal.dk/browserspy/ for how many things they can
> check you against. I investigate also about Imacros that uses a
> browser for automated task and visual click even with batch files, but
> as I mention, it's visual and winbased, so if you want to run batch
> files with imacros you've to have a working X, vmware in linux/macos
> will works but you know, curl is more small/fast and not limited to
> scrap like imacros and is portable, you can even run it on webservers
> or big software. Any clarification of what I said will be appreciated.
>
> //Snippet jahah.c
>
> #include <iostream>
> #include <string>
> #include <fstream>
> #include <vector>
> #include "curl/curl.h"
> #include "curl/types.h"
> #include "curl/easy.h"
>
>
> using namespace std;
>
> // Vettore contenente i cookie
> vector<string> cookies;
>
> // Funzione per l'isolamento del cookie
> void stringTokenizer(const string& s, const char* delim);
>
> // Funzione per scrivere su file l'header della connessione
> size_t write_data(void *, size_t, size_t, void *);
>
> // Funzione per popolare il vettore dei cookie
> void fillCookieVector();
>
> // Funzione che effettua il login e (dovrebbe, speriamoa breve)
> inviare l'sms
> int inviaSMS();
>
> int main()
> {
> cout << "Inviare sms da jajah.com\n" << endl;
>
> inviaSMS();
>
> return 0;
> }
>
> int inviaSMS()
> {
> // File che conterrą l'header
> char *headerfilename = "head.out";
> FILE *headerfile;
>
> // Dati per il login
> string email = "stairzipte_at_kriocoudek.mailexpire.com";
> string password = "qwe123";
>
> // User Agent
> string user_agent = "Mozilla/5.0 (X11; U; Linux x86_64; it;
> rv:1.8.1.1) \
> Gecko/20060601 Firefox/2.0.0.1 (Ubuntu-edgy)";
>
> // Inizializzazione di cURL
> CURL *easyHandle;
> curl_global_init(CURL_GLOBAL_ALL );
> easyHandle = curl_easy_init();
>
> // Si imposta lo UserAgent
> curl_easy_setopt(easyHandle, CURLOPT_USERAGENT, user_agent.c_str());
>
> // La stringa del POST...
> string parametri =
> "__EVENTTARGET=ctl00$ContentBox1$LoginButton&ctl00$ContentBox1$Pwd=" +
> password + "&ctl00$ContentBox1$Email=" + email;
>
> // ...passata a curl nella forma richiesta
> curl_easy_setopt(easyHandle, CURLOPT_POSTFIELDS, parametri.c_str());
>
> // Si imposta l'url del POST
> curl_easy_setopt(easyHandle, CURLOPT_URL,
> "http://www.jajah.com/login.aspx");
> // Tutti i dati ricevuti vengono inviati a questa funzione
> curl_easy_setopt(easyHandle, CURLOPT_WRITEFUNCTION, write_data);
> // Apriamo il file su cui scrivere l'header
> headerfile = fopen(headerfilename,"w");
> if (headerfile == NULL) {
> curl_easy_cleanup(easyHandle);
> return -1;
> }
> // Vogliamo che l'header vada in questo handle
> curl_easy_setopt(easyHandle, CURLOPT_WRITEHEADER, headerfile);
>
> // Invia richiesta
> curl_easy_perform(easyHandle);
>
> // Resetto tutti i parametri di easyHandle
> curl_easy_reset(easyHandle);
>
> // Chiudere il file con l'header recuperato
> fclose(headerfile);
>
> // Chiamiamo la funzione per recuperare i cookie ricevuti
> fillCookieVector();
>
> // GET della pagina www.jajah.com/members/index.aspx
> // Mi serve solo per capire se posso effettivamente navigare nel sito
> // con i privilegi di "member"
> curl_easy_setopt(easyHandle, CURLOPT_USERAGENT, user_agent.c_str());
>
> // Costruisco la stringa contenente i cookie recuperati con
> // la connessione precedente
> string stringa_cookie = "";
> for(int i = 0; i < cookies.size(); i++)
> stringa_cookie += cookies[i] + ";";
>
> // Ormai dovrebbe essere tutto chiaro....
> curl_easy_setopt(easyHandle, CURLOPT_COOKIE, stringa_cookie.c_str());
> curl_easy_setopt(easyHandle, CURLOPT_URL,
> "http://www.jajah.com/members/index.aspx");
> curl_easy_setopt(easyHandle, CURLOPT_WRITEFUNCTION, write_data);
> headerfile = fopen(headerfilename,"w");
> if (headerfile == NULL) {
> curl_easy_cleanup(easyHandle);
> return -1;
> }
> curl_easy_setopt(easyHandle, CURLOPT_WRITEHEADER, headerfile);
> curl_easy_perform(easyHandle);
>
> fclose(headerfile);
>
> fillCookieVector();
>
> // Ripulire curl
> curl_easy_cleanup(easyHandle);
> curl_global_cleanup();
>
>
> return 0;
> }
>
>
> size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
> {
> int written = fwrite(ptr, size, nmemb, (FILE *)stream);
> return written;
> }
>
>
> void stringTokenizer(const string& s, const char* delim)
> {
> int begin_;
> int end_;
> string r;
>
> begin_ = s.find_first_of(delim);
> end_ = s.find_first_of(delim, begin_+1);
>
> r = s.substr(begin_+1, end_-begin_-1);
> // cout << "Token:\n" << r << endl;
> cookies.push_back(r);
> }
>
>
> void fillCookieVector()
> {
> ifstream in("head.out");
> string s;
> while(getline(in, s))
> {
> int n = 0;
> n = s.find("Set-Cookie:");
> if(n >= 0)
> stringTokenizer(s, " ;");
> }
> in.close();
> }
>
> //end
>
Received on 2007-11-07