CommStreams

Usage of the framework, compiler and tools

Re: CommStreams

Postby cfbsoftware » Mon Nov 19, 2018 7:31 am

DGDanforth wrote:I ran Chris' program and it worked!

I'm pleased to hear that - but Ivan deserves the credit for the program :D
cfbsoftware
 
Posts: 30
Joined: Wed Sep 18, 2013 10:06 pm

Re: CommStreams

Postby DGDanforth » Tue Nov 20, 2018 2:08 am

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;
User avatar
DGDanforth
 
Posts: 54
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, CA, U.S.A.

Re: CommStreams

Postby Ivan Denisov » Tue Nov 20, 2018 3:52 pm

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.
User avatar
Ivan Denisov
 
Posts: 238
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: CommStreams

Postby Josef Templ » Tue Nov 20, 2018 8:34 pm

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
Josef Templ
 
Posts: 215
Joined: Tue Sep 17, 2013 6:50 am

Re: CommStreams

Postby DGDanforth » Wed Nov 21, 2018 12:07 am

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.
User avatar
DGDanforth
 
Posts: 54
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, CA, U.S.A.

Re: CommStreams

Postby Ivan Denisov » Wed Nov 21, 2018 2:14 am

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.
User avatar
Ivan Denisov
 
Posts: 238
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: CommStreams

Postby Ivan Denisov » Wed Nov 21, 2018 2:19 am

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 112 times

There is no full support for HTTP 1.1 and no support for SSL, however for most simple cases it is useful :)
User avatar
Ivan Denisov
 
Posts: 238
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: CommStreams

Postby DGDanforth » Wed Nov 21, 2018 8:51 am

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
User avatar
DGDanforth
 
Posts: 54
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, CA, U.S.A.

Re: CommStreams

Postby DGDanforth » Wed Nov 21, 2018 8:54 am

Ivan Denisov wrote:I got Josef's example to work viewtopic.php?f=32&t=208#p1370
User avatar
DGDanforth
 
Posts: 54
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, CA, U.S.A.

Re: CommStreams

Postby Ivan Denisov » Wed Nov 21, 2018 4:31 pm

DGDanforth wrote:There is no module called
CommHttp
OR
CommObxHttp

This modules I packed here :)
viewtopic.php?f=32&t=208#p1363
User avatar
Ivan Denisov
 
Posts: 238
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Previous

Return to Common questions

Who is online

Users browsing this forum: No registered users and 0 guests

cron