Class HttpForm
- content type:
application/x-www-form-urlencoded. posting urlencoded name-value pairs, - content type: MIME-type. for posting user-specified content, and
- content type:
multipart/form-data. for posting multipart data.
Here's a snippet of code illustrating the post of
name value pairs.
HttpForm oForm = new HttpForm();
oForm.SetEncodingType(HttpForm.PostEncodingType.URL_ENCODING);
oForm.AddNameValuePair("fubar", "not yet");
oForm.AddNameValuePair("name", "value");
oForm.AddNameValuePair("submit", "now");
oForm.Post("http://tools_build/scripts/ReadAll.asp");
int nStatus = oForm.GetResponseCode();
String sContentType = oForm.GetResponseType();
String sGotten = oForm.GetResponse();
...
Here's another snippet of code illustrating the post of
data in a user-specified content type and character set.
HttpForm oForm = new HttpForm();
String sSent =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<form>" +
"<name first=\"Ôlêg\" last=\"ÜÇmlæt\"" +
"</name>" +
"</form>";
oForm.SetEncodingType(HttpForm.PostEncodingType.USER_ENCODING);
oForm.AddEncodedData(sSent.getBytes("UTF-8"), "text/xml", "utf-8");
oForm.Post("http://tools_build/scripts/ReadAll.asp");
int nStatus = oForm.GetResponseCode();
String sContentType = oForm.GetResponseType();
String sGotten = oForm.GetResponse();
...
Here's another snippet of code illustrating the post of
multipart data in a user-specified content type and character set.
Author:
Mike P. Tardif
HttpForm oForm = new HttpForm();
oForm.SetEncodingType(HttpForm.PostEncodingType.MULTIPART_ENCODING);
oForm.AddMultipartData(Protocol.SectionDataOption.SECTION_CONTENT_NAME, "fubar".getBytes("US-ASCII"));
oForm.AddMultipartData(Protocol.SectionDataOption.SECTION_CONTENT_VALUE, "not!".getBytes("US-ASCII"));
oForm.AddMultipartData(Protocol.SectionDataOption.SECTION_END, null);
oForm.AddMultipartData(Protocol.SectionDataOption.SECTION_CONTENT_FILE, "protocol/test.html".getBytes("US-ASCII"));
oForm.AddMultipartData(Protocol.SectionDataOption.SECTION_END, null);
oForm.AddMultipartData(Protocol.SectionDataOption.SECTION_CONTENT_NAME, "lotto".getBytes("US-ASCII"));
oForm.AddMultipartData(Protocol.SectionDataOption.SECTION_CONTENT_FILE, "protocol/lotto.wsdl".getBytes("US-ASCII"));
oForm.AddMultipartData(Protocol.SectionDataOption.SECTION_END, null);
oForm.Post(sUrl);
int nStatus = oForm.GetResponseCode();
String sContentType = oForm.GetResponseType();
String sGotten = oForm.GetResponse();
...
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEncodedData(byte[] encodedData, String sContentType, String sCharSet) Add the given encoded data to the form data being accumulated.voidaddHeaderData(String sKey, String sValue) Add a key-value pair to the header datavoidaddMultipartData(Protocol.SectionDataOption eOption, byte[] value) Add the given multipart section to the form data being accumulated.voidaddNameValuePair(String name, String value) Add the given (non-urlencoded) name=value pair to the form data being accumulated.byte[]Get the data response from the last post.intGet the status code response from the last post.Get the content type response from the last post.voidPost accumulated form data to a designated URL.voidsetEncodingType(HttpForm.PostEncodingType ePostEncodingType) Set encoding type.
-
Field Details
-
ChunkSize
public static final int ChunkSize- See Also:
-
MixedSize
public static final int MixedSize- See Also:
-
-
Constructor Details
-
HttpForm
public HttpForm()The default c'tor -- instantiate a HttpForm object.
-
-
Method Details
-
setEncodingType
Set encoding type. One of- URL_ENCODING
for posting urlencoded name-value pairs --
(content type:
application/x-www-form-urlencoded), - USER_ENCODING for posting user-specified content, and
- MULTIPART_ENCODING
for posting multipart data --
(content type:
multipart/form-data)
Resetting this property clears any previously accumulated form data.
Should be called before AddData() is called.
- Parameters:
ePostEncodingType- the encoding type
- URL_ENCODING
for posting urlencoded name-value pairs --
(content type:
-
addNameValuePair
Add the given (non-urlencoded) name=value pair to the form data being accumulated. The name=value pair will be suitably urlencoded, and appended to the data being posted.This method can be called repeatedly to add to the form's data whenever the encoding-type is
application/x-www-form-urlencoded.- Parameters:
name- the namevalue- the value
-
addEncodedData
Add the given encoded data to the form data being accumulated. The encoded data will be appended to the data being posted provided the content type doesn't change.This method can be called repeatedly to add to the form's data.
- Parameters:
encodedData- the encoded data to addsContentType- optional content type for the datasCharSet- optional character set for the data
-
addHeaderData
Add a key-value pair to the header dataThis method can be called repeatedly to add to the header data.
- Parameters:
sKey- the header type (Content-Type, charset etc.)sValue- the header value
-
addMultipartData
Add the given multipart section to the form data being accumulated.This method can be called repeatedly to add to the form's data whenever the encoding-type is
multipart/form-data. Each call creates a separate section of multipart data.The section description will allow the user to specify any one of:
- the content name,
- the content type,
- the content origin (memory or file),
- the content length.
- Parameters:
eOption- the section typevalue- the value
-
post
Post accumulated form data to a designated URL.- Parameters:
sUrl- The designated URL
-
getResponse
public byte[] getResponse()Get the data response from the last post. This excludes all response headers.Calling this method is only meaningful after a Post().
- Returns:
- the response data
-
getResponseCode
public int getResponseCode()Get the status code response from the last post.Calling this method is only meaningful after a Post().
- Returns:
- the response code
-
getResponseType
Get the content type response from the last post.Calling this method is only meaningful after a Post().
- Returns:
- the response type
-