Share via


URL Class

Definition

Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web.

[Android.Runtime.Register("java/net/URL", DoNotGenerateAcw=true)]
public sealed class URL : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable
[<Android.Runtime.Register("java/net/URL", DoNotGenerateAcw=true)>]
type URL = class
    inherit Object
    interface ISerializable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Inheritance
Attributes
Implements

Remarks

Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database or to a search engine. More information on the types of URLs and their formats can be found at: Types of URLhttp://web.archive.org/web/20051219043731/http://archive.ncsa.uiuc.edu/SDG/Software/Mosaic/Demo/url-primer.html

In general, a URL can be broken into several parts. Consider the following example: <blockquote>

http://www.example.com/docs/resource1.html

</blockquote>

The URL above indicates that the protocol to use is http (HyperText Transfer Protocol) and that the information resides on a host machine named www.example.com. The information on that host machine is named /docs/resource1.html. The exact meaning of this name on the host machine is both protocol dependent and host dependent. The information normally resides in a file, but it could be generated on the fly. This component of the URL is called the path component.

A URL can optionally specify a "port", which is the port number to which the TCP connection is made on the remote host machine. If the port is not specified, the default port for the protocol is used instead. For example, the default port for http is 80. An alternative port could be specified as: <blockquote>

http://www.example.com:1080/docs/resource1.html

</blockquote>

The syntax of URL is defined by RFC&nbsp;2396: Uniform Resource Identifiers (URI): Generic Syntaxhttp://www.ietf.org/rfc/rfc2396.txt, amended by RFC&nbsp;2732: Format for Literal IPv6 Addresses in URLshttp://www.ietf.org/rfc/rfc2732.txt. The Literal IPv6 address format also supports scope_ids. The syntax and usage of scope_ids is described here.

A URL may have appended to it a "fragment", also known as a "ref" or a "reference". The fragment is indicated by the sharp sign character "#" followed by more characters. For example, <blockquote>

http://java.sun.com/index.html#chapter1

</blockquote>

This fragment is not technically part of the URL. Rather, it indicates that after the specified resource is retrieved, the application is specifically interested in that part of the document that has the tag chapter1 attached to it. The meaning of a tag is resource specific.

An application can also specify a "relative URL", which contains only enough information to reach the resource relative to another URL. Relative URLs are frequently used within HTML pages. For example, if the contents of the URL: <blockquote>

http://java.sun.com/index.html

</blockquote> contained within it the relative URL: <blockquote>

FAQ.html

</blockquote> it would be a shorthand for: <blockquote>

http://java.sun.com/FAQ.html

</blockquote>

The relative URL need not specify all the components of a URL. If the protocol, host name, or port number is missing, the value is inherited from the fully specified URL. The file component must be specified. The optional fragment is not inherited.

The URL class does not itself encode or decode any URL components according to the escaping mechanism defined in RFC2396. It is the responsibility of the caller to encode any fields, which need to be escaped prior to calling URL, and also to decode any escaped fields, that are returned from URL. Furthermore, because URL has no knowledge of URL escaping, it does not recognise equivalence between the encoded or decoded form of the same URL. For example, the two URLs:<br>

http://foo.com/hello world/ and http://foo.com/hello%20world

would be considered not equal to each other.

Note, the java.net.URI class does perform escaping of its component fields in certain circumstances. The recommended way to manage the encoding and decoding of URLs is to use java.net.URI, and to convert between these two classes using #toURI() and URI#toURL().

The URLEncoder and URLDecoder classes can also be used, but only for HTML form encoding, which is not the same as the encoding scheme defined in RFC2396.

Added in JDK1.0.

Java documentation for java.net.URL.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

URL(String, String, Int32, String, URLStreamHandler)

Creates a URL object from the specified protocol, host, port number, file, and handler.

URL(String, String, Int32, String)

Creates a URL object from the specified protocol, host, port number, and file.

URL(String, String, String)

Creates a URL from the specified protocol name, host name, and file name.

URL(String)

Creates a URL object from the String representation.

URL(URL, String, URLStreamHandler)

Creates a URL by parsing the given spec with the specified handler within a specified context.

URL(URL, String)

Creates a URL by parsing the given spec within a specified context.

Properties

Authority

Gets the authority part of this URL.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Content

Gets the contents of this URL.

DefaultPort

Gets the default port number of the protocol associated with this URL.

File

Gets the file name of this URL.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
Host

Gets the host name of this URL, if applicable.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
Path

Gets the path part of this URL.

PeerReference (Inherited from Object)
Port

Gets the port number of this URL.

Protocol

Gets the protocol name of this URL.

Query

Gets the query part of this URL.

Ref

Gets the anchor (also known as the "reference") of this URL.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)
ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)
UserInfo

Gets the userInfo part of this URL.

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetContent(Class[])

Gets the contents of this URL.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
OpenConnection()

Returns a java.net.URLConnection URLConnection instance that represents a connection to the remote object referred to by the URL.

OpenConnection(Proxy)

Same as #openConnection(), except that the connection will be made through the specified proxy; Protocol handlers that do not support proxing will ignore the proxy parameter and make a normal connection.

OpenStream()

Opens a connection to this URL and returns an InputStream for reading from that connection.

SameFile(URL)

Compares two URLs, excluding the fragment component.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetURLStreamHandlerFactory(IURLStreamHandlerFactory)

Sets an application's URLStreamHandlerFactory.

ToArray<T>() (Inherited from Object)
ToExternalForm()

Constructs a string representation of this URL.

ToString()

Returns a string representation of the object.

(Inherited from Object)
ToURI()

Returns a java.net.URI equivalent to this URL.

UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to