Results 1 to 2 of 2

Thread: Https post

  1. #1
    dongorangoran is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default Https post

    /*
    i get in the headerfiels
    Location=kwick.de/login-fehler.php
    that means iam not logged in
    can somebody explain me why?
    or maybe what i should change?
    thank you for help
    * /


    import java.io.*;
    import java.net.*;
    import java.security.Security.*;
    import com.sun.net.ssl.*;
    import com.sun.*;

    public class sslpost {

    public static void main(String[] args){
    String cuki=new String(); File file = null;
    String query =new String();
    try {
    System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
    java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());


    query = URLEncoder.encode("kwick_username=","UTF-8" )+ URLEncoder.encode("ich","UTF-8");
    query += "&";

    query += URLEncoder.encode("kwick_password=","UTF-8") + URLEncoder.encode("meinpasswort" ,"UTF-8");


    URL url = new URL("https://www.kwick.de/login");


    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setFollowRedirects(true);

    DataOutputStream output = new DataOutputStream( connection.getOutputStream());


    String cookieHeader = connection.getHeaderField("Set-cookie");

    connection.setRequestProperty("Cookie", cookieHeader);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type","application/x-www- form-urlencoded");
    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729) ");
    connection.setRequestProperty("Content-length", String.tovalue(query.length());


    output.write( query.getBytes() );
    output.flush();
    output.close();
    System.out.println("Resp Code:"+connection.getResponseCode());
    System.out.println("Resp Message:"+ connection.getResponseMessage());
    System.out.println(connection.getContentEncoding() );
    System.out.println(connection.getHeaderFields()); /*here i get the location for login mistake*/

    }

    /* connection.setDoInput(true);

    DataInputStream input = new DataInputStream( connection.getInputStream() );


    file = new File("C:/Dokumente und Einstellungen/gast2/Desktop/alte desktop ezeut/studium/eclipse/test.txt");

    System.out.println("Eingehende Datei: " + file.getName());
    FileOutputStream fileOutputStream = new FileOutputStream(file);



    int i = 0;

    while((i = input.read()) != -1){
    fileOutputStream.write(i);
    fileOutputStream.flush();
    }

    input.close();
    fileOutputStream.close();
    }



    */



    catch(Exception e)
    {
    System.out.println( "Something bad just happened." );
    System.out.println( e );
    e.printStackTrace();
    } }
    }

  2. #2
    dongorangoran is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default now i know the problem but how i can handle it

    the proble is:

    output.write( query.getBytes() ); <<<<this order , nothing happens WHY??????

Similar Threads

  1. HTTPS POST Using Java
    By drcman in forum Advanced Java
    Replies: 7
    Last Post: 02-13-2010, 03:19 PM
  2. Replies: 3
    Last Post: 05-04-2009, 04:15 AM
  3. HTTPS & Keytool too
    By jamesEdwards in forum Advanced Java
    Replies: 5
    Last Post: 01-31-2009, 10:25 PM
  4. JDK 1.3 with HTTPS
    By sriram in forum Advanced Java
    Replies: 2
    Last Post: 01-21-2008, 11:51 PM
  5. Replies: 1
    Last Post: 07-14-2007, 06:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •