Re: URL mit Passwort



Michael Konietzka wrote:
Ingo R. Homann wrote:

Hi,

Michael Konietzka wrote:

Ich möchte eine URL-Verbindung öffnen, um eine Text-Datei auszulesen, die per http zugänglich ist, aber eine Authentifizierung erfordert.

Die URL-Klasse scheint das so direkt nicht zu unterstützen:

      URL url = new URL("http://user:password@xxxxxxxxxx";);
      BufferedReader in = new BufferedReader(new InputStreamReader(
          url.openStream()));

Der Code wirft einen 401er.



Zurecht, denn AFAIK ist die Kurzform "user:password@xxxxxxxxxx" laut irgendwelchen HTTP-RFCs auch nicht erlaubt.



In irgendwelchen RFCs hab' ich aber genau das gelesen...


Genauer lesen. ;-)
Aus http://www.faqs.org/rfcs/rfc1738.html

"3.3. HTTP

   The HTTP URL scheme is used to designate Internet resources
   accessible using HTTP (HyperText Transfer Protocol).

   The HTTP protocol is specified elsewhere. This specification only
   describes the syntax of HTTP URLs.

   An HTTP URL takes the form:

      http://<host>:<port>/<path>?<searchpart>

   where <host> and <port> are as described in Section 3.1. If :<port>
   is omitted, the port defaults to 80.  No user name or password is
   allowed.
"
Username und Passwort sind also nicht erlaubt.


Aus RFC1738 (Dank deinem Link gleich gefunden.):

3.1. Common Internet Scheme Syntax

   While the syntax for the rest of the URL may vary depending on the
   particular scheme selected, URL schemes that involve the direct use
   of an IP-based protocol to a specified host on the Internet use a
   common syntax for the scheme-specific data:

        //<user>:<password>@<host>:<port>/<url-path>

   Some or all of the parts "<user>:<password>@", ":<password>",
   ":<port>", and "/<url-path>" may be excluded.  The scheme specific
   data start with a double slash "//" to indicate that it complies with
   the common Internet scheme syntax. The different components obey the
   following rules:

    user
        An optional user name. Some schemes (e.g., ftp) allow the
        specification of a user name.

    password
        An optional password. If present, it follows the user
        name separated from it by a colon.




Username und Password sind also erlaubt. ;-)

cu
.



Relevant Pages

  • This collection already contains an address with scheme http
    ... I get this error when I navigate to a web page hosting a WCF service: ... '/services/myservice.svc' cannot be activated due to an exception during ... address with scheme http. ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: URL encoding api in Java 1.4.2
    ... Scheme: http ... Second is x-www-form-urlencoding of the query part, ... reserved characters in URI syntax, ... http URL scheme that forbids + from the query part, and thus, applying ...
    (comp.lang.java.programmer)
  • Re: website redirect
    ... it redirects you to a russian site. ... Scheme: http ... Query string: ?NPiVWNzFzTnE69h ...
    (comp.security.misc)
  • Re: Preserve scheme of APPH wrapping default HTTP handler
    ... If I wrap the default HTTP handler in my APPH's Start/StartEx method, ... preserve the myproto scheme, instead of replacing it with http, ... HTTP handler under the hood - that's just an implementation detail. ... HTTP URL never reaches the browser (beware HTTP redirects though, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: Preserve scheme of APPH wrapping default HTTP handler
    ... If I wrap the default HTTP handler in my APPH's Start/StartEx method, ... preserve the myproto scheme, instead of replacing it with http, ... HTTP handler under the hood - that's just an implementation detail. ... HTTP URL never reaches the browser (beware HTTP redirects though, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)

Loading