public class HttpForm extends Object
application/x-www-form-urlencoded.
posting urlencoded name-value pairs,
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();
...
| Modifier and Type | Class and Description |
|---|---|
static class |
HttpForm.PostEncodingType |
| Modifier and Type | Field and Description |
|---|---|
static int |
ChunkSize |
static int |
MixedSize |
| Constructor and Description |
|---|
HttpForm()
The default c'tor -- instantiate a HttpForm object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addEncodedData(byte[] encodedData,
String sContentType,
String sCharSet)
Add the given encoded data to the form data being accumulated.
|
void |
addHeaderData(String sKey,
String sValue)
Add a key-value pair to the header data
|
void |
addMultipartData(Protocol.SectionDataOption eOption,
byte[] value)
Add the given multipart section to the form data being accumulated.
|
void |
addNameValuePair(String name,
String value)
Add the given (non-urlencoded) name=value pair to the form
data being accumulated.
|
byte[] |
getResponse()
Get the data response from the last post.
|
int |
getResponseCode()
Get the status code response from the last post.
|
String |
getResponseType()
Get the content type response from the last post.
|
void |
post(String sUrl)
Post accumulated form data to a designated URL.
|
void |
setEncodingType(HttpForm.PostEncodingType ePostEncodingType)
Set encoding type.
|
public static final int ChunkSize
public static final int MixedSize
public void setEncodingType(HttpForm.PostEncodingType ePostEncodingType)
application/x-www-form-urlencoded),
multipart/form-data)
Resetting this property clears any previously accumulated form data.
Should be called before AddData() is called.
ePostEncodingType - the encoding typepublic void addNameValuePair(String name, String value)
This method can be called repeatedly to add to the form's
data whenever the encoding-type is
application/x-www-form-urlencoded.
name - the namevalue - the valuepublic void addEncodedData(byte[] encodedData,
String sContentType,
String sCharSet)
This method can be called repeatedly to add to the form's data.
encodedData - the encoded data to addsContentType - optional content type for the datasCharSet - optional character set for the datapublic void addHeaderData(String sKey, String sValue)
This method can be called repeatedly to add to the header data.
sKey - the header type (Content-Type, charset etc.)sValue - the header valuepublic void addMultipartData(Protocol.SectionDataOption eOption, byte[] value)
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:
eOption - the section typevalue - the valuepublic void post(String sUrl)
sUrl - The designated URLpublic byte[] getResponse()
Calling this method is only meaningful after a Post().
public int getResponseCode()
Calling this method is only meaningful after a Post().
public String getResponseType()
Calling this method is only meaningful after a Post().
Copyright © 2010 - 2020 Adobe. All Rights Reserved