Page 2 of 2

Re: CommStreams

Posted: Mon Nov 19, 2018 7:31 am
by cfbsoftware
DGDanforth wrote:I ran Chris' program and it worked!
I'm pleased to hear that - but Ivan deserves the credit for the program :D

Re: CommStreams

Posted: Tue Nov 20, 2018 2:08 am
by DGDanforth
I am not having much luck in reading bytes from a web site.
I get no errors but the number of bytes returned is zero.
How do I read bytes from "google.com"?

Code: Select all

(s: Stream) ReadBytes (VAR x: ARRAY OF BYTE; beg, len: INTEGER; OUT read: INTEGER), NEW, ABSTRACT;

Code: Select all

s.ReadBytes(x, 0, len, read);

Code: Select all

CONST len = 1024; 

Re: CommStreams

Posted: Tue Nov 20, 2018 3:52 pm
by Ivan Denisov
To communicate with modern websites you should parse responses according HTTP 1.1 standard. There are possible redirects, chunked answers etc.
You can use my solution as I mentioned before viewtopic.php?f=32&t=208#p1363
There are basic support for HTTP standard there.

Re: CommStreams

Posted: Tue Nov 20, 2018 8:34 pm
by Josef Templ
If there are any problems with downloading, it may be required to look into the responses
provided by the http server directly. I don't know if this is possible with Ivan's program.

If it is not possible you can use the sample program I have posted earlier in this topic.
It shows the response header and the body in a text view.
Replacing the URL related info should be obvious, but note that there are several places.

As Ivan pointed out before, you need to know the HTTP 1.1 standard or at least HTTP 1.0
in order to fully understand the meaning of the many optional and/or mandatory parameters passed
in a http request and response header. This can be challenging, very challenging.

Some things, however, can be read directly because it is in plain English.
Important are the error codes at the first line of the response.
200-399 mean some form of success
400 - 499 mean an error i the request
500 - ... mean an error in the server

- Josef

Re: CommStreams

Posted: Wed Nov 21, 2018 12:07 am
by DGDanforth
Josef Templ wrote:If there are any problems with downloading, it may be required to look into the responses
provided by the http server directly. I don't know if this is possible with Ivan's program.

If it is not possible you can use the sample program I have posted earlier in this topic.
I don't see your program on this thread.
Josef Templ wrote:it shows the response header and the body in a text view.
Replacing the URL related info should be obvious, but note that there are several places.

As Ivan pointed out before, you need to know the HTTP 1.1 standard or at least HTTP 1.0
in order to fully understand the meaning of the many optional and/or mandatory parameters passed
in a http request and response header. This can be challenging, very challenging.
I am not to that point yet. I can not see any data from the website.

Re: CommStreams

Posted: Wed Nov 21, 2018 2:14 am
by Ivan Denisov
To get any data you need to ask server to send them.

In my example there is the line:

Code: Select all

stream.Send("GET /" + par$ + " HTTP/1.1" + 0DX + 0AX + "Host: " + host$ + 0DX + 0AX + 0DX + 0AX);
In Josef's example viewtopic.php?f=32&t=208#p1370
there are also the request:

Code: Select all

request := "GET http://greenwoodfarm.com:80/ HTTP/1.0" + CRLF
      + "Host: greenwoodfarm.com" + CRLF
      + CRLF;
which then is sending to server.

Re: CommStreams

Posted: Wed Nov 21, 2018 2:19 am
by Ivan Denisov
Josef Templ wrote:If there are any problems with downloading, it may be required to look into the responses
provided by the http server directly. I don't know if this is possible with Ivan's program.
My example supports redirects and chunked answers. Also support callbacks, what to do with downloaded data.
Снимок экрана от 2018-11-21 09-17-57.png
Снимок экрана от 2018-11-21 09-17-57.png (19.28 KiB) Viewed 10596 times
There is no full support for HTTP 1.1 and no support for SSL, however for most simple cases it is useful :)

Re: CommStreams

Posted: Wed Nov 21, 2018 8:51 am
by DGDanforth
Ivan Denisov wrote:
Josef Templ wrote:If there are any problems with downloading, it may be required to look into the responses
provided by the http server directly. I don't know if this is possible with Ivan's program.
My example supports redirects and chunked answers. Also support callbacks, what to do with downloaded data.
Снимок экрана от 2018-11-21 09-17-57.png
There is no full support for HTTP 1.1 and no support for SSL, however for most simple cases it is useful :)

Code: Select all

MODULE TestDownLoadAndOpen;

	IMPORT
		CommHttp;
	
	PROCEDURE DownLoadAndOpen (url: ARRAY OF CHAR);
	VAR d: CommHttp.Dowing;
	BEGIN
		d := CommHttp.NewDownLoad(url);
		d.onFinish := OpenAsText; 
		(* d.silent := TRUE; (* to hide log view *) *)
		d.Start;
	END DownLoadAndOpen;

END TestDownLoadAndOpen.

"CommObxHttp.DownLoadAndOpen('http://google.com')"
There is no module called
CommHttp
OR
CommObxHttp

Re: CommStreams

Posted: Wed Nov 21, 2018 8:54 am
by DGDanforth
Ivan Denisov wrote: I got Josef's example to work viewtopic.php?f=32&t=208#p1370

Re: CommStreams

Posted: Wed Nov 21, 2018 4:31 pm
by Ivan Denisov
DGDanforth wrote: There is no module called
CommHttp
OR
CommObxHttp
This modules I packed here :)
viewtopic.php?f=32&t=208#p1363