crystyan
asked on
Posting on rawsugar - ciuly
I`m trying to do an automatic process for this http://www.rawsugar.com/register/step1. There is an image there that I have to load in my app. I`ve done that. it works ok, but when I`m posting data it doesn`t work. and I`m not sure why :(((
if u can check my code and make another plsssssssss ?
var
viewstate: String;
count,i,poz:integer;
cookies:tstringlist;
Params: TStrings;
image_url: String;
temp: String;
code: String;
strStream: String;
memStream: TMemoryStream;
Image1: TImage;
jpegimg: TJPEGImage;
id: String;
sunview: String;
L: TStringList;
procedure setcookies;
var j:integer;
begin
count:=IdCookieManager1.Co okieCollec tion.count ;
for j:=1 to count do
IdHTTP1.Request.RawHeaders .Add('Cook ie'+IdHTTP 1.Request. RawHeaders .NameValue Separator+ IdCookieMa nager1.Coo kieCollect ion.Items[ j-1].Cooki eText);
end;
begin
L := TStringList.Create;
Params := TStringList.Create;
Params.Clear;
cookies:=tstringlist.Creat e;
try
idhttp1.AllowCookies:=true ;
idhttp1.HandleRedirects:=t rue;
html:=idhttp1.Get('http://www.rawsugar.com/');// first get; get first cookie(s)
count:=IdCookieManager1.Co okieCollec tion.count ;
for i:=1 to count do
cookies.Add(IdCookieManage r1.CookieC ollection. Items[i-1] .CookieTex t);
// HTML := IdHTTP1.Get('http://www.rawsugar.com/actions/logout');
HTML := IdHTTP1.Get('http://www.rawsugar.com/register/step1');
temp := HTML;
i := pos('id="captchaId" value="', temp);
temp := Copy(temp, i + 22, Length(temp));
i := pos('"', temp);
id := Copy(temp, 1, i - 1);
image_url := 'http://www.rawsugar.com/captcha?c=' + id;
temp := HTML;
i := pos('name="com.sun.faces.V IEW" value="', temp);
temp := Copy(temp, i + 33, Length(temp));
i := pos('"', temp);
sunview := Copy(temp, 1, i - 1);
strStream := IdHTTP1.Get(image_url);
memStream := TMemoryStream.Create;
Image1 := TImage.Create(self);
jpegimg := TJPEGImage.Create;
try
memStream.Write(strStream[ 1], Length(strStream));
memStream.Position := 0;
jpegimg.LoadFromStream(mem Stream);
Image1.Picture.Assign(jpeg img);
Image1.Picture.SaveToFile( IMAGE2_PAT H);
finally
memStream.Free;
jpegimg.Free;
end;
// UrlDownloadToFile(nil, PChar(image_url), PChar(IMAGE_PATH), 0, nil);
SecurityForm.file_ext := '.jpg';
SecurityForm.ShowModal;
SecurityForm.file_ext := '.png';
code := SecurityForm.SecurityCode;
Params.Values['frmRegister :username' ] := Account.LoginName;//[put your user name here];
Params.Values['frmRegister :passcode' ] := '';
Params.Values['frmRegister :fullName' ] := Account.FirstName + ' ' + Account.SecondName;
Params.Values['frmRegister :email'] := Account.Email;
Params.Values['frmRegister :allowCont actByEmail '] := 'on';
Params.Values['frmRegister :password' ] := Account.Password;
Params.Values['frmRegister :passwordR etype'] := Account.Password;
Params.Values['frmRegister :captchaUs erInput'] := code;
Params.Values['captchaId'] := id;
Params.Values['frmRegister :joinIncen tiveProgra m'] := 'on';
Params.Values['frmRegister :agreement '] := 'on';
Params.Values['com.sun.fac es.VIEW'] := sunview;
Params.Values['frmRegister '] := 'frmRegister';
Params.Values['frmRegister :_idcl'] := '';
html := '';
IdHTTP1.HandleRedirects:=f alse;// now this made the buzz, because the cookies were not set when following the redirect
try
HTML := IdHTTP1.Post('http://www.rawsugar.com/pages/register.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.Co okieCollec tion.count ;
for i:=1 to count do
cookies.Add(IdCookieManage r1.CookieC ollection. Items[i-1] .CookieTex t);
setcookies;
html:=idhttp1.Get(IdHTTP1. Response.L ocation);/ / follow redirect
Showmessage(IdHTTP1.Respon se.Locatio n);
end;
end;
finally
end;
Params.Free;
cookies.free;
if u can check my code and make another plsssssssss ?
var
viewstate: String;
count,i,poz:integer;
cookies:tstringlist;
Params: TStrings;
image_url: String;
temp: String;
code: String;
strStream: String;
memStream: TMemoryStream;
Image1: TImage;
jpegimg: TJPEGImage;
id: String;
sunview: String;
L: TStringList;
procedure setcookies;
var j:integer;
begin
count:=IdCookieManager1.Co
for j:=1 to count do
IdHTTP1.Request.RawHeaders
end;
begin
L := TStringList.Create;
Params := TStringList.Create;
Params.Clear;
cookies:=tstringlist.Creat
try
idhttp1.AllowCookies:=true
idhttp1.HandleRedirects:=t
html:=idhttp1.Get('http://www.rawsugar.com/');// first get; get first cookie(s)
count:=IdCookieManager1.Co
for i:=1 to count do
cookies.Add(IdCookieManage
// HTML := IdHTTP1.Get('http://www.rawsugar.com/actions/logout');
HTML := IdHTTP1.Get('http://www.rawsugar.com/register/step1');
temp := HTML;
i := pos('id="captchaId" value="', temp);
temp := Copy(temp, i + 22, Length(temp));
i := pos('"', temp);
id := Copy(temp, 1, i - 1);
image_url := 'http://www.rawsugar.com/captcha?c=' + id;
temp := HTML;
i := pos('name="com.sun.faces.V
temp := Copy(temp, i + 33, Length(temp));
i := pos('"', temp);
sunview := Copy(temp, 1, i - 1);
strStream := IdHTTP1.Get(image_url);
memStream := TMemoryStream.Create;
Image1 := TImage.Create(self);
jpegimg := TJPEGImage.Create;
try
memStream.Write(strStream[
memStream.Position := 0;
jpegimg.LoadFromStream(mem
Image1.Picture.Assign(jpeg
Image1.Picture.SaveToFile(
finally
memStream.Free;
jpegimg.Free;
end;
// UrlDownloadToFile(nil, PChar(image_url), PChar(IMAGE_PATH), 0, nil);
SecurityForm.file_ext := '.jpg';
SecurityForm.ShowModal;
SecurityForm.file_ext := '.png';
code := SecurityForm.SecurityCode;
Params.Values['frmRegister
Params.Values['frmRegister
Params.Values['frmRegister
Params.Values['frmRegister
Params.Values['frmRegister
Params.Values['frmRegister
Params.Values['frmRegister
Params.Values['frmRegister
Params.Values['captchaId']
Params.Values['frmRegister
Params.Values['frmRegister
Params.Values['com.sun.fac
Params.Values['frmRegister
Params.Values['frmRegister
html := '';
IdHTTP1.HandleRedirects:=f
try
HTML := IdHTTP1.Post('http://www.rawsugar.com/pages/register.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.Co
for i:=1 to count do
cookies.Add(IdCookieManage
setcookies;
html:=idhttp1.Get(IdHTTP1.
Showmessage(IdHTTP1.Respon
end;
end;
finally
end;
Params.Free;
cookies.free;
ASKER
hi ciuly,
thanks for advicing me :-)
it still doesn`t work :((( that jsessionid doesn`t appear in the html code (only the first time!!) not sure how they did that, but I got it from the cookies. still when I`m posting to that address it doesn`t work :((. the prob I think is that I don`t post it to the right url as I get the same html as result each time :((
thanks
thanks for advicing me :-)
it still doesn`t work :((( that jsessionid doesn`t appear in the html code (only the first time!!) not sure how they did that, but I got it from the cookies. still when I`m posting to that address it doesn`t work :((. the prob I think is that I don`t post it to the right url as I get the same html as result each time :((
thanks
ASKER
lol ... in fact ... I`m not geting the right cookies ... not sure how`s that happening but in my list of cookies there are some missing ... like search.pref and ident . could u look on my code above and see if I`ve missed something ?
THANKS !
THANKS !
ASKER
I`m not getting all the cookies :(((((((((((
at least when posting from the browser the sniffer shows me more cookies sent there.
and it posts the data at http://www.rawsugar.com/pages/register.faces
at least when posting from the browser the sniffer shows me more cookies sent there.
and it posts the data at http://www.rawsugar.com/pages/register.faces
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this is for my personal use, but I don`t wanna cause u any problems. as I may to give it to some friends.
Thanks anyway if u can`t help me. you`re a TERRIFIC programmer ;)
Thanks anyway if u can`t help me. you`re a TERRIFIC programmer ;)
my best bet is that you see the traffic in the sniffer for all pages that you get and that you send fomr the browser and see whcih one what cookies set.
then make sure your appl;ication does the same.
then check the form source and see if there is anything you need to parse out and use (like viewstate, that session id thing, and maybe who knows what else). also make sure you send out all needed inputs.
from there on, it should work just fine.
that's the best I can give you beside the thing to use twebbrowser for the registration page.
then make sure your appl;ication does the same.
then check the form source and see if there is anything you need to parse out and use (like viewstate, that session id thing, and maybe who knows what else). also make sure you send out all needed inputs.
from there on, it should work just fine.
that's the best I can give you beside the thing to use twebbrowser for the registration page.
ASKER
I don`t wanna user the twebbrowser. I still can`t get the right cookies from step1 page but anyway...I may quit the ideea :-) much more simple lol
THANKS A LOT !
THANKS A LOT !
no problem. sorry I cannot help you. maybe next time :)
method="post" action="/pages/register.fa
that is not visible in your case.
Also, you should install a tcp or at least a http sniffer to see the trafic with your browser and then make sure your application does the same trafic. (this is generally valid)
plus that I am not sure how moral/correct/etc is to make an auto submitter for registration forms. this is regarded in general as not accepted. why not simply use TWebBrowser or TEmmbedWB for registering?