Java ile HTML form POST

Örnek bir kod

 

 

import lotus.domino.*;
import java.net.*;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;

public class JavaAgent extends AgentBase {

public void NotesMain() {

  try {
    String username = "123";
    String password = "456";
    String input = username + ":" + password;
    String encoding = new sun.misc.BASE64Encoder().encode (input.getBytes());

    //Open the URL and read the text into a Buffer
    String urlName = "https://server.org/Export.mvc/GetMeetings?modifiedSince=4/9/2010";
    URL url = new URL(urlName);
    HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();

    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("Content-Length", String.valueOf (encoding.length()));
    connection.setUseCaches(false);
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setAllowUserInteraction(true);
    connection.setRequestProperty("Authorization", "Basic " + encoding);
    connection.setRequestProperty("Cookie", "LocationCode=Geneva");

    connection.connect();

    BufferedReader rd = null;
      try{
        rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      } catch (IOException e) {
        System.out.println("Read failed");
        System.exit(-1);
      }

    String line;
    while((line = rd.readLine()) != null) {
      System.out.println(line.toString());
    }
    rd.close();

    connection.disconnect();

  } catch(Exception e) {
    e.printStackTrace();
  }
}
}
 

 

 
Yorumunuzu Ekleyin

Yükleniyor...