Solved

Post a bookmark to www.rawsugar.com (for ciuly if possible)

Posted on 2006-06-20
13
271 Views
Last Modified: 2010-04-05
Hi there,

Try this:
go on www.rawsugar.com and login as fakedusername and password: mypassword. then there`s a yellow bottom on the right named Tag RawSugar. I hope u can find it. click on it and it will appear a new window with these fields: tags, title, url and note (and some more hidden).

Please tell me how could I post that from my application after I login of course... the login is not very hard. but I think they send crypted data when bookmarking ? or something like that.

here`s the login function that I use:
  PostData('http://www.rawsugar.com/pages/loginAction.faces',
    'login=' + rawsugar_login.User + '&pswd=' + rawsugar_login.Pass +
    '&SubmitLogin=sign-in&__iframe=false&__dg=&__de=&__dc=&__dw=');

  Result := pos('Welcome, ' + rawsugar_login.User, HTML) > 0;

// postdata is posting data to the server and puts the html content into HTML.

hope it makes sence. any questions with no problem !

PLEASE!

Thanks a lot.
0
Comment
Question by:crystyan
  • 8
  • 4
13 Comments
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
as I see, they use application/x-www-form-urlencoded encoding which means you have to make sure that this is done by the component.
check this:
http://www.w3.org/MarkUp/html-spec/html-spec_8.html
The form-urlencoded Media Type

The default encoding for all forms is `application/x-www-form-urlencoded'. A form data set is represented in this media type as follows:
The form field names and values are escaped: space characters are replaced by `+', and then reserved characters are escaped as per [URL]; that is, non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks, as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'.
The fields are listed in the order they appear in the document with the name separated from the value by `=' and the pairs separated from each other by `&'. Fields with null values may be omitted. In particular, unselected radio buttons and checkboxes should not appear in the encoded data, but hidden fields with VALUE attributes present should. (26)

now this encoding type is the default one used for forms, so ... it should work without any problems. strange that it doesn't.

I presume that you keep the logged in state correctly (send all needed cookies).

one easy way to debug such issues is:
- get a packet sniffer, that is best to know the http protocol so that it puts all packets in order and such
- set up the sniffer so that it will sniff the http traffic (some sniffers require explicit configuration for this)
- do the form post with the browser and then check the exchange between browser and server
- now do the same with your application

see what is the difference and fix it ;)

if you can't get it to work, then I'll try to make a sample poject sometime tomorrow (if no one else solves this until then :) )
0
 

Author Comment

by:crystyan
Comment Utility
Hi there,

do know why when I`m using the indy component I get an exception 'HTTP/1.1 302 not Found.' ? with the other component it`s working :(( it drives me crazy ...

Thanks
0
 

Author Comment

by:crystyan
Comment Utility
and the url exists !
0
 

Author Comment

by:crystyan
Comment Utility
and I just found out (using a sniffer) that the component I use sends max 255 chars to the server !!!! WHICH IS NUTS !!!

I should use Indy ... could u make me a sample of a procedure like this

procedure PostHTML(url: String, params: String);

I guess the params should be converted to a TStrings replacing & with #13 ...

Thanks ciuly!
0
 
LVL 17

Expert Comment

by:TheRealLoki
Comment Utility
have you set "HandleRedirects" to true?
0
 

Author Comment

by:crystyan
Comment Utility
lol, that was a problem, thanks. now I can`t figure out why it`s sending max 255 chars ? it simply cuts the rest of the line at Indy too ... so let`s say if we have lots of parameters ... what should I do ?

Thanks
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 28

Accepted Solution

by:
ciuly earned 500 total points
Comment Utility
Hi crystyan,
here is some code to:
- login
- keep persistent connection
- post that form that will add a tag named "test tag"

the code is messy, I didn't spent any time on cleaning it and making it look nicer, there are some copy-pastes there and other ugly operations, but it's working. you can clean it if you like :)

I took this geocaghing project and modified it http://www.ciuly.com/delphi/indy/persistentConnection/index.html . I also added a memo to it so to see what messages are received in the end.
I will post the project sometime when I'll have tim to clean it up.

cheers

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdCookieManager, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP, StdCtrls;

type
  TForm1 = class(TForm)
    IdHTTP1: TIdHTTP;
    IdCookieManager1: TIdCookieManager;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
 Params: TStringList;
 HTML, viewstate: String;
 count,i,poz:integer;
 cookies:tstringlist;

 procedure setcookies;
 var j:integer;
 begin
   count:=IdCookieManager1.CookieCollection.count;
   for j:=1 to count do
     IdHTTP1.Request.RawHeaders.Add('Cookie'+IdHTTP1.Request.RawHeaders.NameValueSeparator+IdCookieManager1.CookieCollection.Items[j-1].CookieText);
 end;

begin
  Params := TStringList.Create;
  cookies:=tstringlist.Create;
  try

    idhttp1.AllowCookies:=true;
    idhttp1.HandleRedirects:=true;

    html:=idhttp1.Get('http://www.rawsugar.com/');// first get; get first cookie(s)
    count:=IdCookieManager1.CookieCollection.count;
    for i:=1 to count do
      cookies.Add(IdCookieManager1.CookieCollection.Items[i-1].CookieText);

    Params.Values['login'] := 'fakedusername';//[put your user name here];
    Params.Values['pswd'] := 'mypassword';//[put your password here];
    Params.Values['__iframe'] := 'true';
    Params.Values['__dg'] := '';
    Params.Values['__de'] := '';
    Params.Values['__dc'] := '';
    Params.Values['__dw'] := '';

    setCookies;
    IdHTTP1.HandleRedirects:=false;// now this made the buzz, because the cookies were not set when following the redirect
    try
      HTML := IdHTTP1.Post('http://www.rawsugar.com/pages/loginAction.faces', Params);// now do the log in
    except on e: EIdHTTPProtocolException do
    begin
      if e.ReplyErrorCode<>302 then
         raise e;
        // now this is the redirect
        count:=IdCookieManager1.CookieCollection.count;
        for i:=1 to count do
          cookies.Add(IdCookieManager1.CookieCollection.Items[i-1].CookieText);

        setcookies;
        html:=idhttp1.Get(IdHTTP1.Response.Location);// follow redirect
      end;
    end;

    // now follows a software redirect made from the script that is returned by the previous call
    count:=IdCookieManager1.CookieCollection.count;// make sure we have all cookies
    for i:=1 to count do
      cookies.Add(IdCookieManager1.CookieCollection.Items[i-1].CookieText);

    setcookies;
    try
      HTML := IdHTTP1.Get('http://www.rawsugar.com/search/');// this is the software redirect
    except on e: EIdHTTPProtocolException do
    begin
      if e.ReplyErrorCode<>302 then// just to be on the safe side
         raise e;
        // now this is the redirect
        count:=IdCookieManager1.CookieCollection.count;
        for i:=1 to count do
          cookies.Add(IdCookieManager1.CookieCollection.Items[i-1].CookieText);

        setcookies;
        html:=idhttp1.Get(IdHTTP1.Response.Location);// follow redirect
      end;
    end;

  except on e: EIdHTTPProtocolException do
    begin
      showmessage(idHTTP1.response.ResponseText);
    end;
  end;
  showmessage('logged in? : '+booltostr(pos('Log out',html)>0,true));// or 'Welcome, fakedusername'
  if pos('Log out',html)>0 then
  begin // now get that search moving
    html := idhttp1.get('http://www.rawsugar.com/tagger/?turl=http%3A%2F%2Fwww.rawsugar.com%2Fsearch%2F&tttl=RawSugar&note=');
    showmessage('loaded tag page? : '+booltostr(pos('Save to My Directory',html)>0,true));

    poz:=pos('name="com.sun.faces.VIEW"',html);
    delete(html,1,poz+25);
    delete(html,1,pos('"',html));
    viewstate:=copy(html,1,pos('"',html)-1);

    Params.clear;
    Params.Values['frmTags%3A_id2'] := 'Everybody';//[put your user name here];
    Params.Values['frmTags%3AselectedTagsEffective'] := 'test tag';//[put your password here];
    Params.Values['frmTags%3AcurrentDocumentUserTitle'] := 'RawSugar';
    Params.Values['frmTags%3AcurrentDocumentUrl'] := 'http://www.rawsugar.com/search/';
    Params.Values['note'] := '';
    Params.Values['emails'] := '';
    Params.Values['frmTags%3A_idg'] := '';
    Params.Values['frmTags%3AtagButton'] := 'Save';
    Params.Values['frmTags%3A_id11'] := 'http://www.rawsugar.com/search/';
    Params.Values['frmTags%3A_id12'] := 'on';
    Params.Values['__tsts'] := '';
    Params.Values['__dg'] := '';
    Params.Values['__de'] := '';
    Params.Values['__dc'] := '';
    Params.Values['__dw'] := '';
    Params.Values['frmTags%3A_id14'] := 'http://www.rawsugar.com/search/';
    Params.Values['emailUpdate'] := '';
    Params.Values['editorInitialized'] := '1';
    Params.Values['com.sun.faces.VIEW'] := viewstate;
    Params.Values['frmTags'] := 'frmTags';

    IdHTTP1.Request.RawHeaders.Add('Referer'+IdHTTP1.Request.RawHeaders.NameValueSeparator+'http://www.rawsugar.com/tagger/?turl=http%3A%2F%2Fwww.rawsugar.com%2Fsearch%2F&tttl=RawSugar&note=');

    count:=IdCookieManager1.CookieCollection.count;
    for i:=1 to count do
      cookies.Add(IdCookieManager1.CookieCollection.Items[i-1].CookieText);
    setcookies;
    try
      HTML := IdHTTP1.Post('http://www.rawsugar.com/pages/tagger.faces',params);
    except on e: EIdHTTPProtocolException do
    begin
      if e.ReplyErrorCode<>302 then// just to be on the safe side
         raise e;
        // now this is the redirect
        count:=IdCookieManager1.CookieCollection.count;
        for i:=1 to count do
          cookies.Add(IdCookieManager1.CookieCollection.Items[i-1].CookieText);

        setcookies;
        html:=idhttp1.Get(IdHTTP1.Response.Location);// follow redirect
      end;
    end;
  end;
  Params.Free;
  cookies.free;
  memo1.lines.text:=html;
end;

end.
0
 

Author Comment

by:crystyan
Comment Utility
thanks a lot ciuly !!! I`ll test it tomorrow cuz today I`m at my parents.
0
 

Author Comment

by:crystyan
Comment Utility
hi ciuly,

this really works :D

but, couldn`t u make this as a procedure that takes as parameters the url and the list of parametrs ? so I can use ... PostHTML(login_url, user_pass); PostHTML(posturl, parmeters_to_post);

this way I can use this function on more sites. do I need 2 different functions for log in and post the bookmark because of the setcookies procedure ?

Thanks!
0
 

Author Comment

by:crystyan
Comment Utility
doesn`t make sence the last reply lol :D

THANKS A LOT !

I`ll post a new question soon as I want to award u more for this. The question should be much simple than this :-)

THANKS, THANKS, THANKS MAN !
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
heh, you can't use the same login/post data/etc function on more than 1 site because
- the parameters will deiffer
- some sites have custom ways of doing login, keeping persistance, posting data, getting data, etc

you can however make some general function/component that will do the login and keep the persisten connection and which knows how to post data to a general web form so you can use it for later posts.
but you will have to be very carefull when you write it.
why? well .. take the geocaching and this rawsugar cases: the first one was pretty strait forward. the second one has a software redirect. software redirects are not something that can be easily detected because they can be done in a variety of ways for which you need a browser like component OR, to write code possible redirection codes .. but will not work in 100% of the cases.

I was thinking about such a copmnonent after getting this question as they are starting to pile up :) so it is obvious that there is a need for such a component, but I just don't have the time right now. maybe in a few eeks. In an case, I wrote it down along with the other projects I have in mond so it will probably get done in a few weeks or months. you can chek my site once a month to see if there is anything new on this matter. (I will have some notification process in place on my site sometime ... in the future :D )

about that other question: EE has a strict policy regarding "awards", so I would say not to bother with putting up a "zombie" question for that. when you will have anotehr real issue and I will be able to help you, you can increase the points if you really want to :)

peace
0
 

Author Comment

by:crystyan
Comment Utility
it`s not a "zombie" question lol :-) It`s a real question that I want u to respond me :-). Anyway ... if someone else answers it`s np. I`ll award him. I don`t want to create u probs here :-)

thanks!
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
oh, sorry for the missunderstanding. well in that case post the link here when you post the question and I'll take a look
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now