Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: IdHTTP: how to read an internet file with wedsite password?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 7 - Last Post: Jan 17, 2018 10:32 AM Last Post By: Xavier Yang Threads: [ Previous | Next ]
xqvier yqng

Posts: 1
Registered: 10/21/12
IdHTTP: how to read an internet file with wedsite password?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 9, 2018 10:48 PM
Hello everyone,
With C++Builder 2010/IdHTTP, I have built a routine for reading/showing the content of a file stored in website.
Here are my codes:

TMemoryStream *MyMem = new TMemoryStream();
AnsiString URLFile = "http://test.free.fr//test.txt";
IdHTTP1->Get(URLFile, MyMem);
MyMem->Seek(0, soFromBeginning);
Memo1->Lines->LoadFromStream(MyMem);
delete MyMem;

This works well if no password on the website "http://test.free.fr".
When there is Login and password needed, I have to enter them manually on a popup menu.
Is there any solution for integrating login and password inside the above codes?
Thank you for your help
Xavier
Xavier Yang

Posts: 17
Registered: 6/28/02
Modified: IdHTTP: how to read an internet file with wedsite password?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 10, 2018 9:29 AM   in response to: xqvier yqng in response to: xqvier yqng
xqvier yqng wrote:
Hello everyone,
With C++Builder 2010/IdHTTP, I have built a routine for reading/showing the content of a file stored in website.
Here are my codes:

TMemoryStream *MyMem = new TMemoryStream();
AnsiString URLFile = "http://test.free.fr//test.txt";
IdHTTP1->Get(URLFile, MyMem);
MyMem->Seek(0, soFromBeginning);
Memo1->Lines->LoadFromStream(MyMem);
delete MyMem;

This works well if no password on the website "http://test.free.fr".
When there is Login and password needed, I have to enter them manually on a popup menu.
Is there any solution for integrating login and password inside the above codes?
Thank you for your help
Xavier

More detail about my initial message: the popup menu is an exception (error "HTTP/1.1 401 Autorisation Required").

Remy Lebeau (Te...


Posts: 9,059
Registered: 12/23/01
Re: IdHTTP: how to read an internet file with wedsite password?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 10, 2018 11:52 AM   in response to: xqvier yqng in response to: xqvier yqng
xqvier yqng wrote:

TMemoryStream *MyMem = new TMemoryStream();
AnsiString URLFile = "http://test.free.fr//test.txt";
IdHTTP1->Get(URLFile, MyMem);
MyMem->Seek(0, soFromBeginning);
Memo1->Lines->LoadFromStream(MyMem);
delete MyMem;

You can simplify that to this:

Memo1->Text = IdHTTP1->Get("http://test.free.fr/test.txt");


When there is Login and password needed, I have to enter them
manually on a popup menu. Is there any solution for integrating
login and password inside the above codes?

Of course there is, but HOW you integrate it depends on whether the
webserver uses HTTP authentication or WebForm authentication.

If HTTP authentication, set the TIdHTTP::Request::UserName and
TIdHTTP::Request::Password properties, and optionally the
TIdHTTP::Request::Authentication or
TIdHTTP::Request::BasicAuthentication properties. TIdHTTP also has
OnSelectAuthorization and OnAuthorization events, if the webserver asks
you for credentials (which you can then use to prompt the user). Also be
sure to enable the hoInProcessAuth flag in the TIdHTTP::HTTPOptions
property.

If Webform authentication, use TIdHTTP::Post() to submit the necessary
HTML WebForm field values using a TStringList or
TIdMultipartFormDataStream, depending on what the login HTML's <form>
and <input> elements ask for.

--
Remy Lebeau (TeamB)
Xavier Yang

Posts: 17
Registered: 6/28/02
Re: IdHTTP: how to read an internet file with wedsite password?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 11, 2018 9:17 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
xqvier yqng wrote:

TMemoryStream *MyMem = new TMemoryStream();
AnsiString URLFile = "http://test.free.fr//test.txt";
IdHTTP1->Get(URLFile, MyMem);
MyMem->Seek(0, soFromBeginning);
Memo1->Lines->LoadFromStream(MyMem);
delete MyMem;

You can simplify that to this:

Memo1->Text = IdHTTP1->Get("http://test.free.fr/test.txt");


When there is Login and password needed, I have to enter them
manually on a popup menu. Is there any solution for integrating
login and password inside the above codes?

Of course there is, but HOW you integrate it depends on whether the
webserver uses HTTP authentication or WebForm authentication.

If HTTP authentication, set the TIdHTTP::Request::UserName and
TIdHTTP::Request::Password properties, and optionally the
TIdHTTP::Request::Authentication or
TIdHTTP::Request::BasicAuthentication properties. TIdHTTP also has
OnSelectAuthorization and OnAuthorization events, if the webserver asks
you for credentials (which you can then use to prompt the user). Also be
sure to enable the hoInProcessAuth flag in the TIdHTTP::HTTPOptions
property.

If Webform authentication, use TIdHTTP::Post() to submit the necessary
HTML WebForm field values using a TStringList or
TIdMultipartFormDataStream, depending on what the login HTML's <form>
and <input> elements ask for.

--
Remy Lebeau (TeamB)

Thank you Remy,
I think it is with HTTP authentication as with your first proposal about TIdHTTP->Request, it works!
Thank you again.

For my personal understandings, I'd like to know what Webform authentication is.
In fact, I meet another issue with TIdHTTP->Request, it works well with public internet connection.
When I use my App in company intranet, it takes long time and meet an error as "Excess of delay".
This is caused by company firewall, I'd like to know how to set more delay in website authentification stage with TIdHTTP.
With my best regards
Xavier
Remy Lebeau (Te...


Posts: 9,059
Registered: 12/23/01
Re: IdHTTP: how to read an internet file with wedsite password?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 12, 2018 10:28 AM   in response to: Xavier Yang in response to: Xavier Yang
Xavier Yang wrote:

For my personal understandings, I'd like to know what Webform
authentication is.

It is when the user has to fill in an input form on an HTML page and
submit it to the server.

In fact, I meet another issue with TIdHTTP->Request, it works well
with public internet connection. When I use my App in company
intranet, it takes long time and meet an error as "Excess of delay".

That is not an Indy error, or even a TCP/HTTP error. What is the EXACT
wording of the error, and how exacly is it being reported to you? An
HTTP error message? A socket error?

This is caused by company firewall, I'd like to know how to set more
delay in website authentification stage with TIdHTTP.

Without knowing where the error is coming from, it is hard to say.

--
Remy Lebeau (TeamB)
Xavier Yang

Posts: 17
Registered: 6/28/02
Re: IdHTTP: how to read an internet file with wedsite password?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 14, 2018 6:43 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Xavier Yang wrote:

For my personal understandings, I'd like to know what Webform
authentication is.

It is when the user has to fill in an input form on an HTML page and
submit it to the server.

In fact, I meet another issue with TIdHTTP->Request, it works well
with public internet connection. When I use my App in company
intranet, it takes long time and meet an error as "Excess of delay".

That is not an Indy error, or even a TCP/HTTP error. What is the EXACT
wording of the error, and how exacly is it being reported to you? An
HTTP error message? A socket error?

This is caused by company firewall, I'd like to know how to set more
delay in website authentification stage with TIdHTTP.

Without knowing where the error is coming from, it is hard to say.

--
Remy Lebeau (TeamB)

Hello Remy,
I think it is socket error. The popupmenu displays simplement: "error of socket 10060, connection delay exceeded" (I don't know how to include a picture in this message).

BR
Xavier
Remy Lebeau (Te...


Posts: 9,059
Registered: 12/23/01
Re: IdHTTP: how to read an internet file with wedsite password?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 15, 2018 8:50 AM   in response to: Xavier Yang in response to: Xavier Yang
Xavier Yang wrote:

I think it is socket error. The popupmenu displays simplement: "error
of socket 10060, connection delay exceeded"

Error code 10060 is WSAETIMEDOUT. Which you typically shouldn't get as
Indy uses blocking sockets and doesn't use socket-level timeouts unless
SSL is being used, or you enable the timeouts manually. Neither are
teh case in your example. However, if you set a non-infinite value to
the ConnectTimeoout property, you might get a timeout error from that,
too. Either way, you company's firewall is clearly blocking data from
flowing, and the socket is timing out internally and reporting an error
back to Indy, which then raises it into your code for handling.

(I don't know how to include a picture in this message).

Post it to the Attachments forum.

--
Remy Lebeau (TeamB)
Xavier Yang

Posts: 17
Registered: 6/28/02
Re: IdHTTP: how to read an internet file with wedsite password?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 17, 2018 10:32 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Xavier Yang wrote:

I think it is socket error. The popupmenu displays simplement: "error
of socket 10060, connection delay exceeded"

Error code 10060 is WSAETIMEDOUT. Which you typically shouldn't get as
Indy uses blocking sockets and doesn't use socket-level timeouts unless
SSL is being used, or you enable the timeouts manually. Neither are
teh case in your example. However, if you set a non-infinite value to
the ConnectTimeoout property, you might get a timeout error from that,
too. Either way, you company's firewall is clearly blocking data from
flowing, and the socket is timing out internally and reporting an error
back to Indy, which then raises it into your code for handling.

Hi Remy,
Thank you for your detail explications.
With the same url, I can read the web file by form identification (iexplorer) though an automatic popup menu.
Can I conclude that my companies' firewall don't block data, it gives only the possibility with form identification.

BR
Xavier
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02