Recent

Author Topic: LNet - HttpClient connection problem  (Read 36655 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1057
LNet - HttpClient connection problem
« on: September 27, 2009, 05:02:35 pm »
Hi,
I have problem with LNet httpclient. I want get html text of some page.
I found examples in LNet package. However, my program as well as examples of the demo throw the error: "Error on connect: connection refused"
This is my code:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
 var
  S: TStrings;
  aHost,
  aURI: String;
  aPort: Word;
begin
  HTTPBuffer := '';
  DecomposeURL(Edit1.Text, aHost, aURI, aPort);
  httpclient.Host := aHost;
  httpclient.URI := aURI;
  httpclient.Port := aPort;
  httpclient.SendRequest;
end;

procedure TForm1.httpclientDoneInput(ASocket: TLHTTPClientSocket);
begin
  ASocket.Disconnect;
end;

procedure TForm1.httpclientError(const msg: string; aSocket: TLSocket);
begin
  MessageDlg(msg, mtError, [mbOK], 0);
end;

function TForm1.httpclientInput(ASocket: TLHTTPClientSocket; ABuffer: pchar;
  ASize: integer): integer;
var
  oldLength: dword;
begin
  oldLength := Length(HTTPBuffer);
  setlength(HTTPBuffer,oldLength + ASize);
  move(ABuffer^,HTTPBuffer[oldLength + 1], ASize);
  Memo1.Text := HTTPBuffer;
  Memo1.SelStart := Length(HTTPBuffer);
  AppendToMemo(Memo1, IntToStr(ASize) + '...');
  Result := aSize; // tell the http buffer we read it all
end;

procedure TForm1.AppendToMemo(aMemo: TMemo; const aText: string);
begin
  aMemo.Append(aText);
  aMemo.SelStart := Length(aMemo.Text);
end;

Regards.

Lazarus Revision 21752 from 2009-09-18. Windows Vista 32bit with SP1. Testet on LNet 0.6.2 and 0.6.3 (SVN version)

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: LNet - HttpClient connection problem
« Reply #1 on: September 30, 2009, 11:43:57 am »
What is in Edit1.Text?

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: LNet - HttpClient connection problem
« Reply #2 on: September 30, 2009, 02:33:07 pm »
URL. I tested with 'http://www.google.com' and 'www.google.com', but in both case I have this same error

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: LNet - HttpClient connection problem
« Reply #3 on: September 30, 2009, 03:21:11 pm »
Does DecomposeURL(Edit1.Text, aHost, aURI, aPort); return the correct port number?

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: LNet - HttpClient connection problem
« Reply #4 on: September 30, 2009, 07:00:07 pm »
Yes, it's port 80. Other variables seems to be ok too (host is empty and URI is a link from Edit1.Text)

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: LNet - HttpClient connection problem
« Reply #5 on: December 01, 2009, 11:15:22 pm »
Solved the problem. URL must be a "http://www.google.com/" instead of "http://www.google.com" (slash is very important)

v-t-l

  • New Member
  • *
  • Posts: 10
Re: LNet - HttpClient connection problem
« Reply #6 on: December 02, 2009, 02:22:52 pm »
I think - it's a bug. Post bugreport, please.

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: LNet - HttpClient connection problem
« Reply #7 on: December 02, 2009, 10:33:04 pm »
Anyone know how to POST with lNet? I want post some XML to serwer.

j4ckr1pp3r

  • Newbie
  • Posts: 4
Re: LNet - HttpClient connection problem
« Reply #8 on: December 05, 2009, 11:04:36 am »
@Dibo:
maybe this is out of topic, have you tried http://devi.web.id/files/httpsynapse.7z

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: LNet - HttpClient connection problem
« Reply #9 on: December 05, 2009, 11:59:50 am »
Yes, but I need sockets for Windows Mobile and synapse have not support. I found only Indy and LNet for Windows Mobile but Indy crashes when I try download the individual HTML pages. Indy is also too large.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1946
Re: LNet - HttpClient connection problem
« Reply #10 on: December 05, 2009, 12:13:28 pm »

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: LNet - HttpClient connection problem
« Reply #11 on: December 05, 2009, 05:42:12 pm »
I tried this once. But I do not know how to use it. I need to replace any files in the standard library synapse? Because now I have two files synsock.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1946
Re: LNet - HttpClient connection problem
« Reply #12 on: December 05, 2009, 05:50:29 pm »
I need to replace any files in the standard library synapse? Because now I have two files synsock.

Yes, you need the synsock.pas that comes with WinCETools afaics.

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: LNet - HttpClient connection problem
« Reply #13 on: December 06, 2009, 10:48:10 am »
I copy WinceTools units into synapse directory and replace synsock.pas. I have error: Can't find unit UnixUtil used by synautil

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1946
Re: LNet - HttpClient connection problem
« Reply #14 on: December 10, 2009, 01:05:58 pm »
I copy WinceTools units into synapse directory and replace synsock.pas. I have error: Can't find unit UnixUtil used by synautil

Change the $ifdef part in the uses clause of synautil. Synapse seems to assume that it's *nix if it's not WIN32.


 

TinyPortal © 2005-2018