--- On Thu, 7/1/10, Jason P Sage <[email protected]> wrote:
> From: Jason P Sage <[email protected]>
> Subject: Re: [Synalist] HttpGetText from Localhost
> To: "Ararat Synapse" <[email protected]>
> Cc: ""Leonardo M. Ramé"" <[email protected]>
> Date: Thursday, July 1, 2010, 12:34 PM
> #1 - You're Welcome for my
> response :)
>
> #2 - I don't think this is a bug per se because cookies use
> the
> semi-colons to separate values on the same line in the
> header... and a
> semi-colon is a valid value for a input element submission
> <input
> type="text" value="Hi;Mom;" /> doesn't technically need
> to by encoded
> though the web browser would anyway; I don't think it would
> look different.
>
> Your fix makes total sense to me. You have a serialized PHP
> array (with
> semicolons) in your cookie; cookies use semi-colons to
> separate data
> bits on one contiguous text line. You are converting the
> semi-colons to
> the codes the uridecode function(s) happily understand and
> return to
> semi-colon's for you... I think you did a great job solving
> this if you
> ask me!
>
> --Jason
> (I'm committing this "gotcha" to memory in case I ever do
> the same thing
> in a cookie!)
Here's my final function, the former works on IE and Firefox, but not on Google
Chrome, this one works in all of them:
function TWebModule1.GetLoginInfo: string;
var
lResponse: TStringList;
lHttpSend: THttpSend;
lSmfCookie: string;
begin
Result := '';
lResponse := TStringList.Create;
lHttpSend := THttpSend.Create;
try
(* Extract the cookie *)
lSmfCookie := Copy(
Request.CookieFields.Text,
Pos('SMFCookie11=', Request.CookieFields.Text),
Length(Request.CookieFields.Text));
(* Remove the SMFCookie11= part *)
lSmfCookie := Copy(lSmfCookie, Pos('=', lSmfCookie) + 1,
Length(lSmfCookie));
(* Remove the last part. *)
lSmfCookie := Copy(lSmfCookie, 0, Pos('}', lSmfCookie));
(* Remove the #10s *)
lSmfCookie := StringReplace(lSmfCookie, #10, ';', [rfReplaceAll]);
lSmfCookie := StringReplace(lSmfCookie, '};', '}', []);
(* Encode *)
lSmfCookie := EncodeUrl(lSmfCookie);
(* EncodeURL function left ":" and ";", I have to encode manually *)
lSmfCookie := StringReplace(lSmfCookie, ':', '%3A', [rfReplaceAll]);
lSmfCookie := StringReplace(lSmfCookie, ';', '%3B', [rfReplaceAll]);
(* Add SMFCookie11= again *)
lHttpSend.Cookies.Add('SMFCookie11=' + lSmfCookie);
(* Send request to the browser *)
lHttpSend.HttpMethod('GET', 'http://localhost/getuser.php');
lResponse.LoadFromStream(lHttpSend.Document);
(* Get the results *)
Result := lResponse.Text;
finally
lResponse.Free;
lHttpSend.Free;
end;
end;
Leonardo M. Ramé
http://leonardorame.blogspot.com
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public