Stay organized with collections
Save and categorize content based on your preferences.
Proxy
open class Proxy
This class represents a proxy setting, typically a type (http, socks) and a socket address. A Proxy
is an immutable object.
Summary
Nested classes |
|
Represents the proxy type.
|
Public constructors |
Creates an entry representing a PROXY connection.
|
Public methods |
open SocketAddress! |
Returns the socket address of the proxy, or null if its a direct connection.
|
Boolean |
Compares this object against the specified object.
|
Int |
Returns a hashcode for this Proxy.
|
open String |
Constructs a string representation of this Proxy.
|
open Proxy.Type! |
Returns the proxy type.
|
Properties |
static Proxy! |
A proxy setting that represents a DIRECT connection, basically telling the protocol handler not to use any proxying.
|
Public constructors
Proxy
Proxy(
type: Proxy.Type!,
sa: SocketAddress!)
Creates an entry representing a PROXY connection. Certain combinations are illegal. For instance, for types Http, and Socks, a SocketAddress must be provided.
Use the Proxy.NO_PROXY
constant for representing a direct connection.
Exceptions |
java.lang.IllegalArgumentException |
when the type and the address are incompatible |
Public methods
address
open fun address(): SocketAddress!
Returns the socket address of the proxy, or null
if its a direct connection.
Return |
SocketAddress! |
a SocketAddress representing the socket end point of the proxy |
equals
fun equals(other: Any?): Boolean
Compares this object against the specified object. The result is true
if and only if the argument is not null
and it represents the same proxy as this object.
Two instances of Proxy
represent the same address if both the SocketAddresses and type are equal.
Parameters |
obj |
the object to compare against. |
Return |
Boolean |
true if the objects are the same; false otherwise. |
hashCode
fun hashCode(): Int
Returns a hashcode for this Proxy.
Return |
Int |
a hash code value for this Proxy. |
toString
open fun toString(): String
Constructs a string representation of this Proxy. This String is constructed by calling toString() on its type and concatenating " @ " and the toString() result from its address if its type is not DIRECT
.
Return |
String |
a string representation of this object. |
type
open fun type(): Proxy.Type!
Returns the proxy type.
Return |
Proxy.Type! |
a Type representing the proxy type |
Properties
NO_PROXY
static val NO_PROXY: Proxy!
A proxy setting that represents a DIRECT
connection, basically telling the protocol handler not to use any proxying. Used, for instance, to create sockets bypassing any other global proxy settings (like SOCKS):
Socket s = new Socket(Proxy.NO_PROXY);
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Proxy\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nProxy\n=====\n\n```\nopen class Proxy\n```\n\n|---|---------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [java.net.Proxy](#) |\n\nThis class represents a proxy setting, typically a type (http, socks) and a socket address. A `Proxy` is an immutable object.\n\nSummary\n-------\n\n| Nested classes ||\n|---|--------------------------------------------------------------------------|\n| | [Type](/reference/kotlin/java/net/Proxy.Type) Represents the proxy type. |\n\n| Public constructors ||\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [Proxy](#Proxy(java.net.Proxy.Type,%20java.net.SocketAddress))`(`type:` `[Proxy.Type](/reference/kotlin/java/net/Proxy.Type)!`, `sa:` `[SocketAddress](/reference/kotlin/java/net/SocketAddress)!`)` Creates an entry representing a PROXY connection. |\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [SocketAddress](/reference/kotlin/java/net/SocketAddress)! | [address](#address())`()` Returns the socket address of the proxy, or `null` if its a direct connection. |\n| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [equals](#equals(kotlin.Any))`(`other:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)?`)` Compares this object against the specified object. |\n| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [hashCode](#hashCode())`()` Returns a hashcode for this Proxy. |\n| open [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | [toString](#toString())`()` Constructs a string representation of this Proxy. |\n| open [Proxy.Type](/reference/kotlin/java/net/Proxy.Type)! | [type](#type())`()` Returns the proxy type. |\n\n| Properties ||\n|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [Proxy](#)! | [NO_PROXY](#NO_PROXY:java.net.Proxy) A proxy setting that represents a `DIRECT` connection, basically telling the protocol handler not to use any proxying. |\n\nPublic constructors\n-------------------\n\n### Proxy\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nProxy(\n type: Proxy.Type!, \n sa: SocketAddress!)\n```\n\nCreates an entry representing a PROXY connection. Certain combinations are illegal. For instance, for types Http, and Socks, a SocketAddress **must** be provided.\n\nUse the `Proxy.NO_PROXY` constant for representing a direct connection.\n\n| Parameters ||\n|--------|------------------------------------------------------------------------------------------------|\n| `type` | [Proxy.Type](/reference/kotlin/java/net/Proxy.Type)!: the `Type` of the proxy |\n| `sa` | [SocketAddress](/reference/kotlin/java/net/SocketAddress)!: the `SocketAddress` for that proxy |\n\n| Exceptions ||\n|--------------------------------------|------------------------------------------------|\n| `java.lang.IllegalArgumentException` | when the type and the address are incompatible |\n\nPublic methods\n--------------\n\n### address\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun address(): SocketAddress!\n```\n\nReturns the socket address of the proxy, or `null` if its a direct connection.\n\n| Return ||\n|------------------------------------------------------------|------------------------------------------------------------------|\n| [SocketAddress](/reference/kotlin/java/net/SocketAddress)! | a `SocketAddress` representing the socket end point of the proxy |\n\n### equals\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun equals(other: Any?): Boolean\n```\n\nCompares this object against the specified object. The result is `true` if and only if the argument is not `null` and it represents the same proxy as this object.\n\nTwo instances of `Proxy` represent the same address if both the SocketAddresses and type are equal.\n\n| Parameters ||\n|-------|--------------------------------|\n| `obj` | the object to compare against. |\n\n| Return ||\n|------------------------------------------------------------------------------------|--------------------------------------------------------|\n| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true` if the objects are the same; `false` otherwise. |\n\n**See Also**\n\n- [java.net.InetSocketAddress#equals(java.lang.Object)](/reference/kotlin/java/net/InetSocketAddress#equals(kotlin.Any)) \n\n### hashCode\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun hashCode(): Int\n```\n\nReturns a hashcode for this Proxy.\n\n| Return ||\n|----------------------------------------------------------------------------|-----------------------------------|\n| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | a hash code value for this Proxy. |\n\n### toString\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun toString(): String\n```\n\nConstructs a string representation of this Proxy. This String is constructed by calling toString() on its type and concatenating \" @ \" and the toString() result from its address if its type is not `DIRECT`.\n\n| Return ||\n|----------------------------------------------------------------------------------|-----------------------------------------|\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | a string representation of this object. |\n\n### type\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun type(): Proxy.Type!\n```\n\nReturns the proxy type.\n\n| Return ||\n|------------------------------------------------------|------------------------------------|\n| [Proxy.Type](/reference/kotlin/java/net/Proxy.Type)! | a Type representing the proxy type |\n\nProperties\n----------\n\n### NO_PROXY\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nstatic val NO_PROXY: Proxy!\n```\n\nA proxy setting that represents a `DIRECT` connection, basically telling the protocol handler not to use any proxying. Used, for instance, to create sockets bypassing any other global proxy settings (like SOCKS):\n\n`Socket s = new Socket(Proxy.NO_PROXY);`"]]