Package totalcross.net
Class HttpStream.Options
- java.lang.Object
-
- totalcross.net.HttpStream.Options
-
- Enclosing class:
- HttpStream
public static class HttpStream.Options extends java.lang.ObjectThis static class is used by one of the constructor methods. It allows to tune the Stream to behave in variant ways.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCHARSET_ISO88591Charset encoding ISO-8859-1static java.lang.StringCHARSET_UTF8Charset encoding UTF-8java.lang.StringdataSet this with your POST/PUT/PATCH/DELETE commands.java.lang.StringdataPrefixSet this with your POST/PUT/PATCH/DELETE commands.java.lang.StringBufferdataSBSet this with your POST/PUT/PATCH/DELETE commands.java.lang.StringdataSuffixSet this with your POST/PUT/PATCH/DELETE commands.booleandisableEncodingThe HttpStream request will ask the server for deflate or gzip encoded response by default.booleandoGetDeprecated.Use httpType insteadbooleandoPostDeprecated.Use httpType insteadjava.lang.StringhttpTypeDefines the http type that will be used.intopenTimeOutThe timeout to open.java.lang.StringpostDataDeprecated.java.lang.StringBufferpostDataSBDeprecated.HashtablepostHeadersThe headers used in POST.java.lang.StringpostPrefixDeprecated.java.lang.StringpostSuffixDeprecated.java.lang.StringproxyAddressBasic support for proxy servers on HttpStream.intproxyPortAssociated to the proxyAddress, proxyPort must match your proxy's port.intreadTimeOutThe read timeout.HashtablerequestHeadersHTTP request headers.protected booleansendDataSocketFactorysocketFactoryCan be used to force HttpStream to use the defined socket factory when creating the underlying connection.intwriteBytesSizeNumber of bytes to write at once.intwriteTimeOutThe write timeout.
-
Constructor Summary
Constructors Constructor Description Options()Constructs a new Options class, from where you change the behaviour of an Http connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetCharsetEncoding()Returns the currently set charset encoding.booleanmustSendData()voidsetBasicAuthentication(java.lang.String user, java.lang.String password)Base64 encodes the username and password given for basic server authenticationvoidsetBasicProxyAuthorization(java.lang.String user, java.lang.String password)Encodes the given username and password in Base64 for basic proxy authorizationvoidsetCharsetEncoding(java.lang.String encoding)Sets the charset encoding to be used by HttpStream.voidsetContent(Multipart multipart)Set the given MIME multipart to be used as the HttpStream POST data.
This method may not be used with post data fields.voidsetContentType(java.lang.String newContentType)Replaces the default Content-Type (application/x-www-form-urlencoded) by the given one.voidsetCookies(Hashtable cookies)Sets the cookies to the ones stored in the given Hashtable.voidsetSendData(boolean sendData)
-
-
-
Field Detail
-
proxyAddress
public java.lang.String proxyAddress
Basic support for proxy servers on HttpStream. You set the variables proxyAddress and proxyPort for this HttpStream instance to get the data thru your proxy.There is yet the SSL part and the "don't use proxy for these address" part. I'm not interested in doing it, but a good resource is: http://www.innovation.ch/java/HTTPClient/advanced_info.html#proxies
I've just tested on my work proxy, using a bluetooth connection, so I'm not sure if it will work with other proxies.
-
proxyPort
public int proxyPort
Associated to the proxyAddress, proxyPort must match your proxy's port. Defaults to -1.
-
requestHeaders
public Hashtable requestHeaders
HTTP request headers. Default header:
User-Agent:/
Note thathost, appended later, is all lower-case.
-
postData
@Deprecated public java.lang.String postData
Deprecated.Set this with your post commands to send a post. The final data string will be the concatenation of postPrefix+postDataSB+postData+postSuffix.- See Also:
postPrefix,postSuffix,postDataSB
-
postDataSB
@Deprecated public java.lang.StringBuffer postDataSB
Deprecated.Set this with your post commands to send a post. The final data string will be the concatenation of postPrefix+postDataSB+postData+postSuffix.- Since:
- TotalCross 1.23
- See Also:
postPrefix,postSuffix
-
postPrefix
@Deprecated public java.lang.String postPrefix
Deprecated.Set this with your post commands to send a post. The final data string will be the concatenation of postPrefix+postDataSB+postData+postSuffix.- Since:
- TotalCross 1.23
- See Also:
postSuffix,postData,postDataSB
-
postSuffix
@Deprecated public java.lang.String postSuffix
Deprecated.Set this with your post commands to send a post. The final data string will be the concatenation of postPrefix+postDataSB+postData+postSuffix.- Since:
- TotalCross 1.23
- See Also:
postPrefix,postData,postDataSB
-
data
public java.lang.String data
Set this with your POST/PUT/PATCH/DELETE commands. The final data string will be the concatenation of dataPrefix+dataSB+data+dataSuffix.- See Also:
dataPrefix,postSuffix,dataSB
-
dataSB
public java.lang.StringBuffer dataSB
Set this with your POST/PUT/PATCH/DELETE commands. The final data string will be the concatenation of dataPrefix+dataSB+data+dataSuffix.- Since:
- TotalCross 1.23
- See Also:
dataPrefix,postSuffix
-
dataPrefix
public java.lang.String dataPrefix
Set this with your POST/PUT/PATCH/DELETE commands. The final data string will be the concatenation of dataPrefix+dataSB+data+dataSuffix.- Since:
- TotalCross 1.23
- See Also:
postSuffix,data,dataSB
-
dataSuffix
public java.lang.String dataSuffix
Set this with your POST/PUT/PATCH/DELETE commands. The final data string will be the concatenation of dataPrefix+dataSB+data+dataSuffix.- Since:
- TotalCross 1.23
- See Also:
dataPrefix,data,dataSB
-
postHeaders
public Hashtable postHeaders
The headers used in POST. These are the default:
Content-Type: application/x-www-form-urlencoded
-
readTimeOut
public int readTimeOut
The read timeout. The default value is 5 seconds.
-
writeTimeOut
public int writeTimeOut
The write timeout. The default value is to be the same value of readTimeOut.
-
openTimeOut
public int openTimeOut
The timeout to open. The default value is 25 seconds.
-
doGet
@Deprecated public boolean doGet
Deprecated.Use httpType insteadSet to false to not issue a GET, but a POST.
-
doPost
@Deprecated public boolean doPost
Deprecated.Use httpType insteadSet to true to issue a post instead of a get. Note that the doGet is automatically set to false.
Here's a sample code:String conn = hostUrl+"survey/RequestArticle.aspx"; HttpStream.Options options = new HttpStream.Options(); options.readTimeOut = 60000; // 1 minute options.writeTimeOut = 50000; // 50 seconds options.openTimeOut = 120000; // 2 minutes options.doPost = true; options.postData = "xml= "; XmlReadableSocket stream = new XmlReadableSocket(new URI(conn),options);
-
httpType
public java.lang.String httpType
Defines the http type that will be used. To issue a POST, do:String conn = hostUrl+"survey/RequestArticle.aspx"; HttpStream.Options options = new HttpStream.Options(); options.readTimeOut = 60000; // 1 minute options.writeTimeOut = 50000; // 50 seconds options.openTimeOut = 120000; // 2 minutes options.httpType = HttpStream.POST; options.postData = "xml=
The default type is GET. You can also define a custom type, like if you want to use restful services. In this case, the header will be set to what you store in the httpType String. Note that, to use another http method, append a space. "; XmlReadableSocket stream = new XmlReadableSocket(new URI(conn),options);HttpStream.Options options = new HttpStream.Options(); options.httpType = "PUT ";
*HttpStream.Options options = new HttpStream.Options(); options.httpType = "CUSTOMMETHOD ";
- Since:
- TotalCross 1.23
- See Also:
HttpStream.GET,HttpStream.POST,HttpStream.PUT,HttpStream.PATCH
-
writeBytesSize
public int writeBytesSize
Number of bytes to write at once. Defaults to 1024.
-
socketFactory
public SocketFactory socketFactory
Can be used to force HttpStream to use the defined socket factory when creating the underlying connection. HttpStream automatically picks the default socket factory for HTTP or HTTPS connections (SocketFactory.getDefault() and SSLContext.getDefault().getSocketFactory() respectively). Use this field only if you wish to replace this default behavior.- Since:
- TotalCross 1.6
-
CHARSET_ISO88591
public static final java.lang.String CHARSET_ISO88591
Charset encoding ISO-8859-1- See Also:
- Constant Field Values
-
CHARSET_UTF8
public static final java.lang.String CHARSET_UTF8
Charset encoding UTF-8- See Also:
- Constant Field Values
-
sendData
protected boolean sendData
-
disableEncoding
public boolean disableEncoding
The HttpStream request will ask the server for deflate or gzip encoded response by default. This behaviour can be changed by either setting this field to true or by explicitly adding the header Accept-Encoding to the request.
Please notice that HttpStream automatically detects and inflates the response received from the stream if a supported content encoding (deflate or gzip) is detected.
-
-
Constructor Detail
-
Options
public Options()
Constructs a new Options class, from where you change the behaviour of an Http connection. Sets thepostHeadersto:Content-Type: application/x-www-form-urlencoded User-Agent: platform / deviceId
You can override these if you want, just put the new values in the Hashtable or use other methods available in this class.
-
-
Method Detail
-
setCharsetEncoding
public void setCharsetEncoding(java.lang.String encoding)
Sets the charset encoding to be used by HttpStream.- Parameters:
encoding- the cjarset encoding to be set. Must be either "ISO-8859-1" or "UTF-8".
-
getCharsetEncoding
public java.lang.String getCharsetEncoding()
Returns the currently set charset encoding.- Returns:
- the charset encoding
-
setContentType
public void setContentType(java.lang.String newContentType)
Replaces the default Content-Type (application/x-www-form-urlencoded) by the given one.
-
setCookies
public void setCookies(Hashtable cookies)
Sets the cookies to the ones stored in the given Hashtable.
-
setBasicAuthentication
public void setBasicAuthentication(java.lang.String user, java.lang.String password)Base64 encodes the username and password given for basic server authentication- Parameters:
user- The username for the server. Passing null disables authentication.password- The password for the username account on the server. Passing null disables authentication.
-
setBasicProxyAuthorization
public void setBasicProxyAuthorization(java.lang.String user, java.lang.String password)Encodes the given username and password in Base64 for basic proxy authorization- Parameters:
user- the username for the proxy. Passing null disables proxy authorization.password- the password for the proxy. Passing null disables proxy authorization.- Since:
- TotalCross 1.27
-
setContent
public void setContent(Multipart multipart)
Set the given MIME multipart to be used as the HttpStream POST data.
This method may not be used with post data fields. These fields are ignored by the HttpStream after this method is used.- Parameters:
multipart- the multipart to be set as POST data- Since:
- TotalCross 1.25
-
setSendData
public void setSendData(boolean sendData)
-
mustSendData
public boolean mustSendData()
-
-