--- On Thu, 7/1/10, Jason P Sage <[email protected]> wrote: > From: Jason P Sage <[email protected]> > Subject: Re: [Synalist] HttpGetText from Localhost > To: [email protected] > Date: Thursday, July 1, 2010, 7:29 AM > Hello Leonardo. I have to ask > the simple question: Does the URL you > are specifying work with a browser? I mean 404 error sounds > like a > server response.
Jason, thanks for answering. Let me tell you a little bit more about the problem, now I'm in an advanced stage since the last time, so the problem as changed. First of all, the server is Linux on i386, and the PHP app is just a little script that encapsulates some logic that allows the know some data about the logged-in user, profile, etc. When I say logged-in, I mean, logged in to an SMF forum. If I log in to the SMF forum, a Cookie is created, then when I call the little PHP app, it uses some high level functions to access user data. I debugged this with FireBug, and found the browser sends the Cookie back and forth to the server, that's why the php script allways work. On the other hand, my app is a CGI created with fcl-web, that needs to call this php script passing the Cookie to let the php script to know how to handle user data. What I found, is the cookie data has many #10 chars, and must be EncodeURL before sending to the server, the problem now is that I think Synapse's EncodeURL function isn't working as expected. The encoded Cookie is this: SMFCookie11=a%3A4%3A%7Bi%3A0%3Bs%3A4%3A%225179%22%3Bi%3A1%3Bs%3A40%3A%22b0102aa33e0d25c7f46ded1dc9d61b82e9d30175%22%3Bi%3A2%3Bi%3A1277993716%3Bi%3A3%3Bi%3A0%3B%7D <--- Let's call this (1) If I decode it with this tool, http://meyerweb.com/eric/tools/dencoder/ , I get this: SMFCookie11=a:4:{i:0;s:4:"5179";i:1;s:40:"b0102aa33e0d25c7f46ded1dc9d61b82e9d30175";i:2;i:1277993716;i:3;i:0;} In my CGI I receive the Cookie in its decoded form, with many #10 chars that I have to remove to format the Cookie the same way as I need, then Encode it to send to the server, the problem is that I get this: SMFCookie11=a:4:%7Bi:0;s:4:%225179%22;i:1;s:40:%22b0102aa33e0d25c7f46ded1dc9d61b82e9d30175%22;i:2;i:1277993716;i:3;i:0;%7D Instead of the one in (1). If you look a little closer, Synapse's encoder is skipping ":" and ";". To get the deserved results, I had to replace ":" by "%3A" and ";" by "%3B". Is this a bug??? Problem solved!. This is my code: ---------------- 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, Pos('}', lSmfCookie) - 1); (* 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
