LNet - HttpClient connection problem lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Dibo · 2009-09-27 15:02 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 · 2009-09-30 09:43 What is in Edit1.Text? ---------------------------------------------------------------------- Dibo · 2009-09-30 12:33 URL. I tested with 'http://www.google.com' and 'www.google.com', but in both case I have this same error ---------------------------------------------------------------------- Vincent Snijders · 2009-09-30 13:21 Does DecomposeURL(Edit1.Text, aHost, aURI, aPort); return the correct port number? ---------------------------------------------------------------------- Dibo · 2009-09-30 17:00 Yes, it's port 80. Other variables seems to be ok too (host is empty and URI is a link from Edit1.Text) ---------------------------------------------------------------------- Dibo · 2009-12-01 22:15 Solved the problem. URL must be a "http://www.google.com/" instead of "http://www.google.com" (slash is very important) ---------------------------------------------------------------------- v-t-l · 2009-12-02 13:22 I think - it's a bug. Post bugreport, please. ---------------------------------------------------------------------- Dibo · 2009-12-02 21:33 Anyone know how to POST with lNet? I want post some XML to serwer. ---------------------------------------------------------------------- j4ckr1pp3r · 2009-12-05 10:04 @Dibo: maybe this is out of topic, have you tried http://devi.web.id/files/httpsynapse.7z ---------------------------------------------------------------------- Dibo · 2009-12-05 10:59 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 · 2009-12-05 11:13 Quote from: Dibo on December 05, 2009, 11:59:50 amYes, but I need sockets for Windows Mobile and synapse have not support. http://www.mail-archive.com/synalist- public@lists.sourceforge.net/msg01871.html ---------------------------------------------------------------------- Dibo · 2009-12-05 16:42 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 · 2009-12-05 16:50 Quote from: Dibo on December 05, 2009, 05:42:12 pmI 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 · 2009-12-06 09:48 I copy WinceTools units into synapse directory and replace synsock.pas. I have error: Can't find unit UnixUtil used by synautil ---------------------------------------------------------------------- theo · 2009-12-10 12:05 Quote from: Dibo on December 06, 2009, 10:48:10 amI 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. ---------------------------------------------------------------------- Dibo · 2009-12-12 19:48 Thanks! Now works great. Synapse has always been my favorite sockets and now I can use them even on mobile devices ---------------------------------------------------------------------- picstart · 2009-12-13 15:39 Synapse is robust. Often developers of open software prefer to push the frontier since that's where the glory is. New features get the kudos. It maybe that for every execution of a new feature there are hundreds of executions of basic function code. A failure in a basic function casts doubt on the creditability of the whole project whereas the absence of a new feature is missed by only a very few. In spite of the fact that only the frontiersmen need advanced features the race goes on and reliability is a lower priority.  Anyway synapse developers have bucked the trend and created a reliable package. ---------------------------------------------------------------------- theo · 2009-12-13 20:08 @picstart: completely agree. Except "..synapse developers have..". Synapse is a one man show like many great and reliable packages. (see VirtualTrees etc..) ---------------------------------------------------------------------- theo · 2009-12-28 16:36 Quote from: Dibo on December 12, 2009, 08:48:35 pmThanks! Now works great. Synapse has always been my favorite sockets and now I can use them even on mobile devices Could you show what you have changed in the synapse sources? I don't need it personally now, but others might be interested. Thanks. ---------------------------------------------------------------------- Dibo · 2009-12-28 18:22 Of course! I copied all files from WinceTools.zip (in the annex if someone couldn't to find) into the synapse directory, replacing the existing ones. In the file synautil I changed directive IFDEF WIN32 to IFDEF WINCE (I did not have time to add OR condition so I use "Replace" function ) . And thats all ---------------------------------------------------------------------- paulvh · 2010-05-25 06:43 I get the same problem ("Error on connect: connection refused") even if I put a slash behind the URL. Lazarus 0.9.28.2, FPC 2.2.4, lNET SVN, Windows 7 Installed Synapse and with one line of code could fetch a web page, no problem. Of course it is blocking, etc. so it would be nice if lNet can be fixed. The demo, httpclienttest.lpi also dies with "Error creating SSL CTX: SSLCTXNew". If I delete the SSL component it runs, but with connection refused error on any URL. Firewall is turned off but I expect it has to do with Windows 7. ---------------------------------------------------------------------- Dibo · 2010-05-25 09:22 @paulvh - this version don't resolve this problem jet? http://www.lazarus.freepascal.org/index.php/topic,9378.0.html QuoteURL parsing rewrite (pesky trailing "/" no longer a problem Cheesy) ---------------------------------------------------------------------- Almindor · 2010-05-27 09:28 paulvh: Connection refused is only used when recv returns 0 which means the OS says so. Perhaps it's a windows 7 thing, but I don't own nor do I plan to own a windows 7 so I can't debug this. Your SSL problem could be due to OpenSSL libs. What version did you install? ---------------------------------------------------------------------- Loesje · 2010-09-02 18:48 I have the same problem as paulvh on Linux (FC11) - latest fpc-lnet svn, fpc-trunk (2.5.1) and Lazarus (2.9.29) ---------------------------------------------------------------------- Almindor · 2011-03-02 20:32 There were two bugs in DecomposeURL: 1. The result value should be true only if it's a https 2. The port should default to 80 for http, 443 for https (was only 80 all the time, caused the SSL error) 3. [optiona] fixed error reporting from SSL (reported rubbish before) and also added whole-error-stack SSL reports to get through. Both bugs were related to me changing the DecomposeURL code to use ParseURI from FPC and not properly handling these situations in the new setting. Fixed now in trunk. Thank you for reporting the issue ---------------------------------------------------------------------- Dibo · 2011-03-02 21:26 @Up. Exactly. I wrote my own DecomposeURL. Another bug is that DecomposeURL cut variables in links. Example: "www.someweb.com/srcipt.php?var1=value1&var2=value2" return ""www.someweb.com/srcipt.php" (or something that, I am not in my computer) ---------------------------------------------------------------------- Almindor · 2011-03-02 21:28 Fixed as well, am using the TURI.Params now if they are present. I will probably use TURI internally eventually in HTTP to evade these problems. ---------------------------------------------------------------------- Shebuka · 2011-06-08 15:25 Hi, I think i'v found a bug in new version, if URL has white spaces (like http://my.server.com/folder/some file of mine.txt) it is not encoded on SendRequest so it produce 400 Bad Request error even if file exists. (and if i manually replace spaces with %20 they are decoded internally in URLparser so again produce 400 Bad Request error, in 0.6.4 with old DecomposeURL it was working well) ---------------------------------------------------------------------- Almindor · 2011-06-12 07:27 Fixed in trunk, thanks