URLConnection: setDoInput(boolean doinput) : URLConnection « java.net « Java by API






URLConnection: setDoInput(boolean doinput)

 
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();
  }

}

           
         
  








Related examples in the same category

1.URLConnection: connect() throws IOException
2.URLConnection: getContentEncoding()
3.URLConnection: getContentType()
4.URLConnection: getExpiration()
5.URLConnection: getHeaderFields()
6.URLConnection: getHeaderField(int n)
7.URLConnection: getHeaderFieldKey(int n)
8.URLConnection: getInputStream()
9.URLConnection: getIfModifiedSince()
10.URLConnection: getLastModified()
11.URLConnection: getURL()
12.URLConnection: setAllowUserInteraction(boolean allowuserinteraction)
13.URLConnection: setDoOutput(boolean dooutput)
14.URLConnection: setIfModifiedSince(long ifmodifiedsince)
15.URLConnection: setRequestProperty(String key, String value)
16.URLConnection: setUseCaches(boolean usecaches)