cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Unsuccessful Login

From: Mambo Knave <mamboknave_at_gmail.com>
Date: Tue, 16 Nov 2010 10:52:35 -0800

 No, there is no <meta http-equiv=...> in the html source.

It really seems it's not a problem of those Logon.x and Logon.y. Let's set
them both to zero, like pressing Enter instead of clicking the mouse.

So, like Mozilla does, I do POST:
"USER=myUSRid&PASSWORD=myPASSwd&TARGET=%2Fe%2Ft%2Finvest%2Foptionorderentry&Logon.x=0&Logon.y=0"

In order to get the necessary cookies PRIOR to posting I'm now "visiting"
the Login page with curl_easy_perform. After that I set CURLOPT_POSTFIELDS
and do curl_easy_perform again.

Results: exactly like before. Instead of permitting the logging in, the Host
outputs the Login page with this warning message displayed on it: "You have
requested access to a customer-only feature"

Again, I know quite nothing about html/java/php and all that. All what I
need is to retrieve some data from ETrade without doing a manual login.

Here below my the updated script.

If some kind soul would want to take a deeper look, I can provide userid and
password of an empty account created for test purposes only.

Paolo

=======================================================

#include <curl/curl.h>
#include <curl/easy.h>
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

int main(void)
{
const string LoginPage = "https://us.etrade.com/e/t/user/login";

const string stPostLogin =
"USER=myUSRid&PASSWORD=myPASSwd&TARGET=%2Fe%2Ft%2Fpfm%2Fportfolioview&Logon.x=0&Logon.y=0";

const string UserAgent =
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027
Ubuntu/9.10 (karmic) Firefox/3.6.12";

CURL *sessionA;
CURLcode result;

FILE *CookieFile, *HeaderFile, *Page2File;

const char *CookiesBag = "Cookies.txt";

CookieFile = fopen(CookiesBag,"w");
HeaderFile = fopen("Header.html","w");
Page2File = fopen("Page.html","w");

curl_global_init(CURL_GLOBAL_ALL);

sessionA = curl_easy_init();

if(sessionA) {

    curl_easy_setopt(sessionA, CURLOPT_USERAGENT, UserAgent.c_str());

    curl_easy_setopt(sessionA, CURLOPT_VERBOSE, 1);
    curl_easy_setopt(sessionA, CURLOPT_FOLLOWLOCATION, 1);

    curl_easy_setopt(sessionA, CURLOPT_WRITEHEADER, HeaderFile);

    curl_easy_setopt(sessionA, CURLOPT_AUTOREFERER, 1);
    curl_easy_setopt(sessionA, CURLOPT_REFERER, LoginPage.c_str());

    curl_easy_setopt(sessionA, CURLOPT_COOKIELIST, "ALL"); //erase "ALL"
cookies
    curl_easy_setopt(sessionA, CURLOPT_COOKIEJAR, CookiesBag);
    curl_easy_setopt(sessionA, CURLOPT_COOKIEFILE, CookiesBag);

    curl_easy_setopt(sessionA, CURLOPT_URL, LoginPage.c_str());
    result = curl_easy_perform(sessionA); // "visiting" first

    curl_easy_setopt(sessionA, CURLOPT_WRITEDATA, Page2File);

    curl_easy_setopt(sessionA, CURLOPT_POSTFIELDS, stPostLogin.c_str());
    result = curl_easy_perform(sessionA); // then posting

    curl_easy_cleanup(sessionA);

        }
return 0;
}

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-11-16