Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-07

lnet and http headers

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ADTEC Pty Ltd

Hi

I'm currently using synapse to connect to a website that will send a redirect instruction in one of the http headers. Unfortunately, I can't get it to work in 64bit. I'm trying to convert to the lnet package but can't see how to access the headers. Does anyone know if the package is capable of returning individual headers? If so, do you have an example I can view?

Thanks

Graham

Reply by email

ik
to ADTEC Pty Ltd
Hi

Hi,

Show quoted text 8 lines
I'm currently using synapse to connect to a website that will send a redirect instruction in one of the http headers. Unfortunately, I can't get it to work in 64bit. I'm trying to convert to the lnet package but can't see how to access the headers. Does anyone know if the package is capable of returning individual headers? If so, do you have an example I can view?

https://github.com/ik5/xmlrpc-client-ui/blob/master/src/untxmlrpc_client.pp#L347

But why not to publish the problematic code so we can help you better ?

Show quoted text 5 lines
Thanks Graham

Ido

Show quoted text 7 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110706/a2c85435/attachment.html>

Reply by email

Krzysztof
to ik

Hi,

I am using synapse on 32 and 64 bit Windows and Linux without problems. Can you publish some code here?

About lNET: They are very good sockets (non blocking mode is strong point for me), but they are too much "typed". If you want serve non standard status codes or headers, you must add it manually to the source (lhttp.pp unit) and recompile package. That's why I returned to synapse. But to answer for your question:
1. If you want read some header, you must add OnProcessHeaders event:

procedure TForm1.LHTTPClientComponent1ProcessHeaders(ASocket:
TLHTTPClientSocket);
begin
  Memo1.Append(ASocket.Parameters[hpContentLength]);
end;
2. If you want add header, you must call
LHTTPClient1.AddExtraHeader('Content-length: 123');

Notify that there is no way to clear this headers (if you want call next request on this same http client but with different headers). So I wrote patch for this, but not accepted yet:
http://bugs.freepascal.org/view.php?id=18954

Regards

2011/7/6 ik

Show quoted text 49 lines
On Wed, Jul 6, 2011 at 12:09, ADTEC (Pty) Ltd wrote: > Hi > Hi, > > I'm currently using synapse to connect to a website that will send a > redirect instruction in one of the http headers. Unfortunately, I > can't get it to work in 64bit. I'm trying to convert to the lnet > package but can't see how to access the headers. Does anyone know if > the package is capable of returning individual headers? If so, do you > have an example I can view? > https://github.com/ik5/xmlrpc-client-ui/blob/master/src/untxmlrpc_client.pp#L347 But why not to publish the problematic code so we can help you better ? > > Thanks > > Graham > Ido > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110706/d59f742e/attachment.html>

Reply by email

ADTEC Pty Ltd
Hi

Hi,

Show quoted text 8 lines
I'm currently using synapse to connect to a website that will send a redirect instruction in one of the http headers. Unfortunately, I can't get it to work in 64bit. I'm trying to convert to the lnet package but can't see how to access the headers. Does anyone know if the package is capable of returning individual headers? If so, do you have an example I can view?

https://github.com/ik5/xmlrpc-client-ui/blob/master/src/untxmlrpc_client.pp#L347

But why not to publish the problematic code so we can help you better ?

Show quoted text 5 lines
Thanks Graham

Ido

Thanks, Ido.

However, the way I see your code, it adds headers to send to the server. I need to read headers coming back from the server.

Below is my code using synapse in a Win32 environment. The url variable is set earlier. This code connects to the server and, because I'm in the process of changing servers, responds with a header "X-Redirect" that I use to query the next server in line. The code works perfectly in 32 bit, but when I try to compile synapse in win64, it fails because the synapse code assumes that if it is not WIN32, it is being compiled for linux and wants the BaseUnix and Unix files.

  while bDone = False do
  begin
    frmConnecting := TfrmConnecting.Create(Self);
    frmConnecting.Show;
    frmConnecting.Update;
    HTTP := THTTPSend.Create;
    try
      frmConnecting.Label1.Caption := 'Connecting to server...';
      frmConnecting.Update;
      bResult := HTTP.HTTPMethod('GET', url);
      if bResult then
      begin
        frmConnecting.Label1.Caption := 'Checking result...';
        frmConnecting.Update;
        for i:=0 to HTTP.Headers.Count -1 do
        begin
             if LeftStr(HTTP.Headers[i], 9) = 'X-Result:' then
                sResult := RightStr(HTTP.Headers[i],
length(HTTP.Headers[i]) - 10);
             if LeftStr(HTTP.Headers[i], 11) = 'X-Redirect:' then
                url := RightStr(HTTP.Headers[i], length(HTTP.Headers[i]) - 12);
             if leftstr(HTTP.Headers[i],32) = 'Content-disposition:
attachment;' then
             begin
                  sFilename := RightStr(HTTP.Headers[i],
length(HTTP.Headers[i]) - pos('filename=', HTTP.Headers[i]) - 9);
                  sFilename := LeftStr(sFilename, length(sFilename) - 1);
             end;
        end;
        if sFilename  '' then
        begin
              frmConnecting.Label1.Caption := 'Downloading file...';
              frmConnecting.Update;
              try
                 fStream := TFileStream.Create(gPriceFileDir + '\' +
sFilename, fmOpenWrite or fmCreate);
                 fStream.Seek(0, soFromBeginning);
                 fStream.CopyFrom(HTTP.Document, 0);
              finally
                 fStream.Free;
              end;
        end;
      end;
    finally
      HTTP.Free;
    end;
    frmConnecting.Close;
    // Set result message
    bDone := True;
    msg := '';
    Case StrToInt(LeftStr(sResult, 1)) of
         0 : msg := sFilename + ' successfully downloaded.';
         1 : msg := 'We have no record of you purchasing the software.';
         2 : msg := 'Your subscription has expired. No data downloaded.';
         3 : msg := 'Invalid username or password. No data downloaded.';
         4 : bDone := False;
    else
         msg := 'Unrecognized response code. Please check for software
upgrade.';
    end;
    if Length(msg) > 0 then
       ShowMessage(msg);
  end;

Thanks
Graham

Reply by email

Ludo Brands
to ADTEC Pty Ltd
Show quoted text 5 lines
server in line. The code works perfectly in 32 bit, but when I try to compile synapse in win64, it fails because the synapse code assumes that if it is not WIN32, it is being compiled for linux and wants the BaseUnix and Unix files.

In synsock.pas, synautil.pas and ssl_openssl_lib add

{$IFDEF WIN64}
  {$DEFINE WIN32}        //for win64
{$ENDIF}

in the beginning of the unit, before any other {$IFDEF}.

That worked perfectly for me.

Ludo

Reply by email