Class HttpPost


java.lang.Object

   |

   +----HttpPost


public class HttpPost
extends Object
A class representing for posting information to web servers. For example:

    HttpPost hpost= new hpost("http://130.9.15.26/vrs/hello.cgi");

 

See Also:
util, io

Constructor Index

 o HttpPost(String)
Opens connection to the URL specified in String.

Method Index

 o end()
Submit necessary characters to indicate the end of Post method
 o init()
Opens connection to the URL specified.
 o readResponse()
Get the response from the server.
 o sendField(String, String)
Send a field to the server
 o sendFile(String, String)
Send a file to the server
 o setPassword(String)
For web site that requires authentication only.
 o setProxy(String, String)
Change the proxy setting.
 o setUser(String)
For web site that requires authentication only.
 o useProxy(boolean)
By default, this class use the proxy for all HTTP connections.

Constructors

 o HttpPost

 public HttpPost(String urlstr)

Opens connection to the URL specified in String.

Methods

 o init

 public void init()

Opens connection to the URL specified. Opens the DataOutputStream and DataInputStream.

Returns:
None.
Throws: MalformedURLException
if the index is not in the range 0 to length()-1.
See Also:
openConnection
 o sendFile

 public void sendFile(String fileName,

                      String value)

Send a file to the server

Parameters:
fileName - is the name of the file to send. value is the name of the field that accepts the file.
Returns:
None.
Throws: StringIndexOutOfRangeException
if the index is not in the range 0 to length()-1.
See Also:
charValue
 o sendField

 public void sendField(String fieldName,

                       String value)

Send a field to the server

Parameters:
value - is the content to send. fieldName is the name of the field that accepts the file.
Returns:
None.
Throws: StringIndexOutOfRangeException
if the index is not in the range 0 to length()-1.
See Also:
Character
 o end

 public void end()

Submit necessary characters to indicate the end of Post method

Returns:
None.
See Also:
close
 o readResponse

 public DataInputStream readResponse()

Get the response from the server.

Returns:
DataInputStream
See Also:
getInputStream
 o useProxy

 public void useProxy(boolean proxy)

By default, this class use the proxy for all HTTP connections. To disable proxy, use useProxy(false)

Parameters:
true - to enable proxy connection; false to disable.
Returns:
None.
See Also:
 o setProxy

 public void setProxy(String proxy,

                      String portnum)

Change the proxy setting. By the default, the proxy name is proxy and the port number is 3128

Parameters:
proxy - is the name of proxy, eg "proxy.singnet.com.sg'. portnum is the port number of the proxy.
Returns:
None.
See Also:
 o setPassword

 public void setPassword(String pwd)

For web site that requires authentication only. User need to supply the password.

Parameters:
pwd - is the password string.
Returns:
None.
 o setUser

 public void setUser(String username)

For web site that requires authentication only. User need to supply the User ID.

Parameters:
username - is the user ID string, eg "Anonymous"
Returns:
None.