1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

Send and Receive Data From and To HTTPS Server

Last Updated:

  1. Ravi_Aegis

    Ravi_Aegis New Member This Topic's Starter

    Apr 7, 2010
    Likes Received:
    Hi All,

    I am Ravi.

    I have created an Simple Program, goal of that program is to make connection to HTTPS server and send data to https server and receive data from https server.

    in that case i am successful to make a connection to Https server and also able to read data what server sends to client, but when from my client program i am trying to send data to Https server that time there is no error but in server when i try to read that data then there is no data available in Server input stream to read.

    This is my Code of client,

    package com.mobhype.sdk;

    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io_OutputStreamWriter;
    import java.net.URL;
    import java.net.URLConnection;
    import java.net.URLEncoder;
    import java.security.KeyManagementException;
    import java.security.NoSuchAlgorithmException;
    import java.security.SecureRandom;

    import javax.net.ssl.HttpsURLConnection;
    import javax.net.ssl.SSLContext;
    import javax.net.ssl.TrustManager;
    import javax.net.ssl.X509TrustManager;

    import android.app.Activity;
    import android.content.Intent;

    public class MobHypeSDK {

    public String responseString;
    public String responseURL;
    String url;
    MultiFormatReader multiFormatReader;
    RGBMonochromeBitmapSource source;
    Result r;
    String decryptedText;

    public void sendImageToHTTPS(String path)
    //String url = "https://localhost:8443/MobHypeServer?actionType=sendImage";

    String cuki=new String();


    TrustManager easyTrustManager = new X509TrustManager()
    public java.security.cert.X509Certificate[] getAcceptedIssuers()
    return null;
    public void checkClientTrusted(
    java.security.cert.X509Certificate[] chain, String authType)
    throws java.security.cert.CertificateException {
    // TODO Auto-generated method stub
    public void checkServerTrusted(
    java.security.cert.X509Certificate[] chain, String authType)
    throws java.security.cert.CertificateException {
    // TODO Auto-generated method stub

    URL url = new URL("https://localhost:8443/MobHypeServer?actionType=sendImage");
    SSLContext sslcontext = SSLContext.getInstance("TLS");
    sslcontext.init(null, new TrustManager[] { easyTrustManager }, null);
    HttpsURLConnection shuc = (HttpsURLConnection) url.openConnection();
    System.out.println("Connection Code--------->" + shuc.getResponseCode());
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    String str = in.readLine();
    while(str != null)
    System.out.println("DATA From Https Server------>" + str);
    str = in.readLine();
    OutputStreamWriter out = new OutputStreamWriter(shuc.getOutputStream());

    out.write("OUT WriteFirst.....");
    out.write("OUT WriteFirst.....");
    out.flush(); out.close();
    System.out.println("Data Are Written Successfully.......");
    catch(Exception e)
    This above is Client Code,

    This is my Server Code,

    package com.mobhype.server;

    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io_ObjectInputStream;
    import java.io_ObjectOutputStream;
    import java.io_OutputStreamWriter;
    import java.util.List;

    import javax.servlet.ServletException;
    import javax.servlet.ServletInputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    * Servlet implementation class MobHypeServer
    public class MobHypeServer extends HttpServlet

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    String actionType = request.getParameter("actionType");
    System.out.println("This is DO POST METHOD............");
    System.out.println("Action Type's value....."+actionType);
    ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream());
    oos.writeObject("First DATA From Server");
    oos.writeObject("Second DATA From Server");
    oos.writeObject("Thirs DATA From Server");
    catch(Exception e)

    please any idea where i am doing wrong in this code.

    all ideas are welcome
    Thank you


Share This Page