Share via


URLConnection Class

Definition

The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL.

[Android.Runtime.Register("java/net/URLConnection", DoNotGenerateAcw=true)]
public abstract class URLConnection : Java.Lang.Object
[<Android.Runtime.Register("java/net/URLConnection", DoNotGenerateAcw=true)>]
type URLConnection = class
    inherit Object
Inheritance
URLConnection
Derived
Attributes

Remarks

The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL. In general, creating a connection to a URL is a multistep process:

<center><table border=2 summary="Describes the process of creating a connection to a URL: openConnection() and connect() over time."> <tr><th>openConnection()</th> <th>connect()</th></tr> <tr><td>Manipulate parameters that affect the connection to the remote resource.</td> <td>Interact with the resource; query header fields and contents.</td></tr> </table> ----------------------------&gt; <br>time</center>

<ol> <li>The connection object is created by invoking the openConnection method on a URL. <li>The setup parameters and general request properties are manipulated. <li>The actual connection to the remote object is made, using the connect method. <li>The remote object becomes available. The header fields and the contents of the remote object can be accessed. </ol>

The setup parameters are modified using the following methods: <ul> <li>setAllowUserInteraction<li>setDoInput<li>setDoOutput<li>setIfModifiedSince<li>setUseCaches</ul>

and the general request properties are modified using the method: <ul> <li>setRequestProperty</ul>

Default values for the AllowUserInteraction and UseCaches parameters can be set using the methods setDefaultAllowUserInteraction and setDefaultUseCaches.

Each of the above set methods has a corresponding get method to retrieve the value of the parameter or general request property. The specific parameters and general request properties that are applicable are protocol specific.

The following methods are used to access the header fields and the contents after the connection is made to the remote object: <ul> <li>getContent<li>getHeaderField<li>getInputStream<li>getOutputStream</ul>

Certain header fields are accessed frequently. The methods: <ul> <li>getContentEncoding<li>getContentLength<li>getContentType<li>getDate<li>getExpiration<li>getLastModifed</ul>

provide convenient access to these fields. The getContentType method is used by the getContent method to determine the type of the remote object; subclasses may find it convenient to override the getContentType method.

In the common case, all of the pre-connection parameters and general request properties can be ignored: the pre-connection parameters and request properties default to sensible values. For most clients of this interface, there are only two interesting methods: getInputStream and getContent, which are mirrored in the URL class by convenience methods.

More information on the request properties and header fields of an http connection can be found at: <blockquote>

<a href="http://www.ietf.org/rfc/rfc2616.txt">http://www.ietf.org/rfc/rfc2616.txt</a>

</blockquote>

Invoking the close() methods on the InputStream or OutputStream of an URLConnection after a request may free network resources associated with this instance, unless particular protocol specifications specify different behaviours for it.

Added in JDK1.0.

Java documentation for java.net.URLConnection.

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

URLConnection(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

URLConnection(URL)

Constructs a URL connection to the specified URL.

Properties

AllowUserInteraction

Returns the value of the allowUserInteraction field for this object. -or- Set the value of the allowUserInteraction field of this URLConnection.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Connected

If false, this connection object has not created a communications link to the specified URL.

ConnectTimeout

Returns setting for connect timeout. -or- Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection.

Content

Retrieves the contents of this URL connection.

ContentEncoding

Returns the value of the content-encoding header field.

ContentLength

Returns the value of the content-length header field.

ContentLengthLong

Returns the value of the content-length header field as a long.

ContentType

Returns the value of the content-type header field.

Date

Returns the value of the date header field.

DefaultAllowUserInteraction

Returns the default value of the allowUserInteraction field. -or- Sets the default value of the allowUserInteraction field for all future URLConnection objects to the specified value.

DefaultUseCaches

Returns the default value of a URLConnection's useCaches flag. -or- Sets the default value of the useCaches field to the specified value.

DoInput

Returns the value of this URLConnection's doInput flag. -or- Sets the value of the doInput field for this URLConnection to the specified value.

DoOutput

Returns the value of this URLConnection's doOutput flag. -or- Sets the value of the doOutput field for this URLConnection to the specified value.

Expiration

Returns the value of the expires header field.

FileNameMap

Returns a FileNameMap implementation suitable for guessing a content type based on a URL's "file" component. -or- Sets the FileNameMap.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
HeaderFields

Returns an unmodifiable Map of the header fields.

IfModifiedSince

Returns the value of this object's ifModifiedSince field. -or- Sets the value of the ifModifiedSince field of this URLConnection to the specified value.

InputStream

Returns an input stream that reads from this open connection.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
LastModified

Returns the value of the last-modified header field.

OutputStream

Returns an output stream that writes to this connection.

PeerReference (Inherited from Object)
Permission

Returns a permission object representing the permission necessary to make the connection represented by this object.

ReadTimeout

Returns setting for read timeout. -or- Sets the read timeout to a specified timeout, in milliseconds.

RequestProperties

Returns an unmodifiable Map of general request properties for this connection.

ThresholdClass

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

ThresholdType

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

Url

The URL represents the remote object on the World Wide Web to which this connection is opened.

URL

Returns the value of this URLConnection's URL field.

UseCaches

Returns the value of this URLConnection's useCaches field. -or- Sets the value of the useCaches field of this URLConnection to the specified value.

Methods

AddRequestProperty(String, String)

Adds a general request property specified by a key-value pair.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Connect()

Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.

ConnectAsync()
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[])

Retrieves the contents of this URL connection.

GetDefaultRequestProperty(String)
Obsolete.

Returns the value of the default request property.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetHeaderField(Int32)

Returns the value for the n<sup>th</sup> header field.

GetHeaderField(String)

Returns the value of the named header field.

GetHeaderFieldDate(String, Int64)

Returns the value of the named field parsed as date.

GetHeaderFieldInt(String, Int32)

Returns the value of the named field parsed as a number.

GetHeaderFieldKey(Int32)

Returns the key for the n<sup>th</sup> header field.

GetHeaderFieldLong(String, Int64)

Returns the value of the named field parsed as a number.

GetRequestProperty(String)

Returns the value of the named general request property for this connection.

GuessContentTypeFromName(String)

Tries to determine the content type of an object, based on the specified "file" component of a URL.

GuessContentTypeFromStream(Stream)

Tries to determine the type of an input stream based on the characters at the beginning of the input stream.

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)
SetContentHandlerFactory(IContentHandlerFactory)

Sets the ContentHandlerFactory of an application.

SetDefaultRequestProperty(String, String)
Obsolete.

Sets the default value of a general request property.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetRequestProperty(String, String)

Sets the general request property.

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

Returns a string representation of the object.

(Inherited from Object)
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