Dealing with Slow Connections
HttpUrlConnection
offers two methods to help with slow connections:
connection.setConnectTimeout(6000); connection.setReadTimeout(6000);
Call setConnectTimeout()
to adjust the timeout when establishing the network connection to the remote site. The value you give as input should be in milliseconds. Call setReadTimeout()
to adjust the timeout when reading data on the input stream. Again, provide the new timeout input in milliseconds.
Requesting Parameters
With many web services, you'll have to input parameters when making a request. HTTP parameters are encoded as name-value pairs. For example, consider the following:
String path = "http://example.com?name1=value1&name2=value2";
In this case, name1
is the name of a parameter, and so is name2
. The value of the name1
parameter is value1
, and the value of name2
is value2
. Parameters are separated by an ampersand character, &
.
Note
If the parameter values are simple...