URLConnection: setDoOutput(boolean dooutput)
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.URL;
import java.net.URLConnection;
public class MainClass {
public static void main(String args[]) throws Exception {
String query = "name=yourname&email=youremail@yourserver.com";
URLConnection uc = new URL("http:// your form ").openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setAllowUserInteraction(false);
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
// The POST line, the Accept line, and
// the content-type headers are sent by the URLConnection.
// We just need to send the data
dos.writeBytes(query);
dos.close();
// Read the response
DataInputStream dis = new DataInputStream(uc.getInputStream());
String nextline;
while ((nextline = dis.readLine()) != null) {
System.out.println(nextline);
}
dis.close();
}
}
Home
Java Book
Networking
Java Book
Networking
URLConnection:
- URLConnection
- URLConnection: connect() throws IOException
- URLConnection: getContentEncoding()
- URLConnection: getExpiration()
- URLConnection: getHeaderFields()
- URLConnection: getHeaderField(int n)
- URLConnection: getHeaderFieldKey(int n)
- URLConnection: getIfModifiedSince()
- URLConnection: getLastModified()
- URLConnection: getURL()
- URLConnection: setAllowUserInteraction(boolean allowuserinteraction)
- URLConnection: setDoOutput(boolean dooutput)
- URLConnection: setIfModifiedSince(long ifmodifiedsince)
- URLConnection: setRequestProperty(String key, String value)
- URLConnection: setUseCaches(boolean usecaches)