Page 1 of 1

ReceiveHTTPFile() with userID and password, possible?

Posted: Sun Apr 11, 2010 7:35 pm
by Jacobus
Hello, is it possible to download a file with ID and password on http://... ??
The following code doesn't work. (example)

Code: Select all

InitNetwork()
Filezip$ = SaveFileRequester("Where to save filename.zip ?", "", "", 0)
 If Filezip$
  user.s = "userid"
  pass.s = "passw"
  If ReceiveHTTPFile("http://"+user+":"+pass+"@www.domain.com/filename.zip", Filezip$)
    Debug "Download done"
  Else
    Debug "Download failed"
  EndIf 
 EndIf

Re: ReceiveHTTPFile() with userID and password, possible?

Posted: Sun Apr 11, 2010 8:45 pm
by Rook Zimbabwe
Does this work:

Code: Select all

user$ = "user"
pass$ = "pass"
ReceiveHTTPFile("http://"+user$+":"+pass$+"@www.domain.com/filename.zip", "C:\filename.zip")
all by its lonesome in the program?

If not... it might be your user/password because I think that is for FTP but I am unsure...
have you tried:

Code: Select all

ReceiveFTPFile(#PB_Any, "http://"+user$+":"+pass$+"@www.domain.com/filename.zip", "C:\filename.zip") , Asynchronous)
:mrgreen:

Re: ReceiveHTTPFile() with userID and password, possible?

Posted: Mon Apr 12, 2010 6:58 am
by Jacobus
Thanks. I shall try as soon as possible.

Re: ReceiveHTTPFile() with userID and password, possible?

Posted: Mon Apr 12, 2010 10:01 am
by a.ross
I would say no, not the way you doing it according to this snippet I found on the interweb:
Of the predefined schemes listed (http, ftp, news, nntp, telnet, gopher
wais, mailto, file, prospero), only ftp: and telnet: URLs use the login
form, which allows for a password. http: uses only hostport.

So the syntax in the spec doesn't allow for what you want. See:
http://www.w3.org/hypertext/WWW/Address ... ssing.html
http://www.w3.org/hypertext/WWW/Addressing/rfc1738.txt

In the HTTP 1.0 protocol (with Basic Authentication) the user name and
password are not sent as part of the URL on the GET line, but rather in a
"Authorization:" header sent in response to a "WWW-Authenticate:" header
sent when a prior request failed.

The HTTP spec also agrees that the http: URL has the form:

http_URL = "http:" "//" host [ ":" port ] [ abs_path ]

See:
http://www.w3.org/hypertext/WWW/Protocols/Overview.html
http://www.w3.org/hypertext/WWW/Protoco ... /spec.html

While you could write a custom client that would do a GET with a username
and password by sending the right headers with the request, trying to use
the generic URL syntax to do this is not going to work.

(There are other authorization schemes in the works besides Basic, but it
is still widely used.)

(Also note: While the spec for telnet URLs allows for a username and
password, you are unlikely to find this implemented.)

Re: ReceiveHTTPFile() with userID and password, possible?

Posted: Mon Apr 12, 2010 9:11 pm
by TerryHough
Not with the built in PB command ReceiveHTTPFile() I don't believe.

But, look at this link for a way to do it.
http://www.purebasic.fr/english/viewtop ... e+download

Re: ReceiveHTTPFile() with userID and password, possible?

Posted: Tue Apr 13, 2010 8:04 am
by Jacobus
Thanks at all.
@TerryHough, The Luis code is just perfect for my needs. The multiple ways in which it placed at our disposal are very sufficient. Luis if you pass through here, be thanked for your sharing. :)

Re: ReceiveHTTPFile() with userID and password, possible?

Posted: Tue Apr 13, 2010 2:14 pm
by TerryHough
I failed to show you the link to a related topic that may be useful too.

http://www.purebasic.fr/english/viewtop ... p+download

I agree. Luis did us all a big favor with his code. I've much appreciated it.