|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jscience.net.CGI
public class CGI
The class CGI provides a convenient way to post parameters to a web-based CGI script.
Here is a complete code example that assumes that the script specified with the given URL takes two input values: 'name' and 'text':
try {
URL url = new URL("http://myserver/cgi-bin/myscript.cgi");
CGI cgi = new CGI(url);
cgi.setHeader("cookie", "my cookie value");
HashMap params = new HashMap();
params.put("name", "Me");
params.put("text", "first line\nsecond line\n");
int response = cgi.post(params);
if (response != 200) {
System.out.println("something went wrong");
}
// see the complete response the script sent back
System.out.println(cgi.getResponse());
} catch (IOException e) { e.printStackTrace(); }
Note that you do not need to 'escape' the values, as this is done
by the post(Map) method.
| Constructor Summary | |
|---|---|
CGI(java.net.URL cgiUrl)
requires a URL based on the HTTP protocol specifying the script you are posting to |
|
| Method Summary | |
|---|---|
void |
clearHeaders()
|
java.util.Map<java.lang.String,java.lang.String> |
getHeaders()
|
java.lang.String |
getResponse()
can be used to retrieve the full text of the last server response after the post(Map) method was called. |
int |
post(java.util.Map<java.lang.Object,java.lang.Object> parameters)
posts the given parameters to the instance's URL via POST. |
int |
post(java.lang.String content)
posts the encoded string directly to the URL per HTTP POST. |
int |
post(java.lang.String[] param,
java.lang.String[] value)
posts the given parameter/value pairs to the embedded URL in the exact specified order. |
int |
post(java.lang.String parameter,
java.lang.String value)
convenience method to post a single parameter/value pair |
void |
setHeader(java.lang.String key,
java.lang.String value)
allows to add additional header information to the request or overwrite existing ones. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CGI(java.net.URL cgiUrl)
throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException - if the protocol is not HTTP| Method Detail |
|---|
public java.lang.String getResponse()
post(Map) method was called.
post(Map)
public void setHeader(java.lang.String key,
java.lang.String value)
URLConnection.setRequestProperty(String,String)public java.util.Map<java.lang.String,java.lang.String> getHeaders()
public void clearHeaders()
public int post(java.lang.String parameter,
java.lang.String value)
throws java.io.IOException
java.io.IOException
public int post(java.lang.String[] param,
java.lang.String[] value)
throws java.io.IOException
The value entries must not be encoded; this is done within this method.
To retrieve the full text returned by the server after you called
this method, use getResponse()
java.io.IOExceptiongetResponse()
public int post(java.util.Map<java.lang.Object,java.lang.Object> parameters)
throws java.io.IOException
getResponse()
java.io.IOExceptiongetResponse()
public int post(java.lang.String content)
throws java.io.IOException
getResponse()
java.io.IOExceptiongetResponse()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||