Go Back   Android Forums > Android Discussion > Android Applications
Android Applications All the information you could ever want about Android Applications. Learn about apps and get help with them... all here! New apps can be found and announced in the Applications Announcements forum linked below.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
LinkBack Thread Tools
Old April 7th, 2010, 06:22 AM   #1 (permalink)
New Member
Thread Author (OP)
Join Date: Apr 2010
Posts: 2
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Post Send and Receive Data From and To HTTPS Server

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

System.setProperty("java.protocol.handler.pkgs","c om.sun.net.ssl.internal.www.protocol");
System.setProperty("javax.net.ssl.trustStore","key store");

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.setDefaultSSLSocketFactory(sslc ontext.getSocketFactory());
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

Ravi_Aegis is offline  
Last edited by Ravi_Aegis; April 7th, 2010 at 08:42 AM.
Reply With Quote
sponsored links

Go Back   Android Forums > Android Discussion > Android Applications
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

All times are GMT -5. The time now is 02:22 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.