Results 1 to 2 of 2
  1. #1
    stodds is offline Member
    Join Date
    Dec 2010
    Rep Power

    Default Authenticating for a java POST request

    Hey guys,

    I've run myself into a bit of a corner here trying to make a post request to a server. I've been told that we are using Public Key authentication with HTTPS and SSL client certifications, but I just am unable to authenticate with the server to make my request.

    Currently I am using and HttpURLConnection, but when I run the program I am returned a notification of an http response of 401 (unauthorized).

    I was hoping someone here would know a little bit more about authentication in java than I do, and I could get a push in the right direction.

    The following is the code for the connection that I have, but with some details (IP address, username/password) hidden.

    String userPassword = "username" + ":" + "password";
    String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBy tes());

    URL cisco = new URL("https://urlofserver");
    HttpURLConnection ciscoCon = (HttpURLConnection) cisco.openConnection();
    ciscoCon.setRequestProperty("Authorization", "Basic " + encoding);

    OutputStreamWriter out = new OutputStreamWriter(ciscoCon.getOutputStream());

  2. #2
    stodds is offline Member
    Join Date
    Dec 2010
    Rep Power


    OK, after taking a new direction and trying a socket connection I now have the following:

    socket = new Socket("", 8443);
    out = socket.getOutputStream();
    in = socket.getInputStream();
    // send the request to the host
    // read the response from the host
    StringBuffer sb = new StringBuffer(2048);
    bArray = new byte[2048];
    int ch = 0;
    int sum = 0;
    while ( (ch = != -1 ){
    sum += ch;
    sb.append(new String(bArray, 0, ch));
    // output the response to the standard out

    The issue now being that I am trying to connect to a specific port, but am not connecting at the top level directory (I am connecting into the axl folder).

    How can I get a socket connection to work out when I am unable to use the standard constructor because I want to get into this other top level folder?

Similar Threads

  1. HTTP Post Request from Java
    By Darrarski in forum New To Java
    Replies: 10
    Last Post: 06-05-2010, 06:22 PM
  2. Invocation of Restful services thru POST request
    By userj2ee in forum Advanced Java
    Replies: 0
    Last Post: 05-06-2010, 12:40 PM
  3. Replies: 3
    Last Post: 05-04-2009, 04:15 AM
  4. First post as per request
    By happyknappy in forum Introductions
    Replies: 3
    Last Post: 07-30-2008, 02:33 AM
  5. Replies: 1
    Last Post: 07-14-2007, 06:15 PM

Tags for this Thread

Posting Permissions

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