
So the software I am developing in my leisure time is about to complete. Past weekend I worked on it's security aspects and implemented many things like encryption and encapsulation of byte code, Encryption of POST data, Generation of unique ID for each system using my software and the licensing part. I will try to explain each part in my coming posts.
Earlier I demonstrated How to display Splash Screen in Java. Today I will show how I am sending simple data from my Java code to my PHP page on Web server.
package www.isumitjha.com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
class Test {
public static void main(String args[]) {
try {
// opening a connection to the site
URL url = new URL("http://api.isumitjha.com/example.php");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Setting the DoOutput flag true for using output
con.setDoOutput(true);
con.setRequestMethod("POST");
// Encoding the POST data
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("Hello", "UTF-8") + "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("World", "UTF-8");
OutputStreamWriter osw = new OutputStreamWriter(
con.getOutputStream());
// Sending parameter to site
osw.write(data);
osw.flush();
con.getInputStream();
System.out.println("RESPONSE CODE = " + con.getResponseCode());
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String line = null;
while ((line = in .readLine()) != null) {
System.out.println(line);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Now let's see the simple PHP code that prints all value received via POST request.
<?php
foreach ($_POST as $key => $data) {
echo $data." ";
}
?>
So this is how I am sending data to my server. In my next post I will show you how to encrypt POST data using Advanced Encryption Standard and receive response from server in JSON format.
I hope you enjoyed reading :)
PHP is widely used programming language used for developing dynamic websites and web applications. You can get clear insights on PHP programming language at training
ReplyDeleteRegards,
PHP Training in Chennai|PHP Training Chennai
Day by day I am getting new things and learn new concept through your blogs, I am feeling so confidants, and thanks for your informative blog keep your post as updated one...
ReplyDeleteRegards,
web designing course in chennai|website designing training
The strategy you have posted on this technology hepled me to get into the next level and had lot of informations in it.
ReplyDeletesalesforce training in chennai | salesforce training institute in chennai
The strategy you have posted on this technology hepled me to get into the next level and had lot of informations in it. Python is one of the basic level programming and is very important one.
ReplyDeletePython Training in Chennai | Python Course in Chennai
Excellent Post! Java is such a beautiful language to learn, if you have skills in java, you can easily switch your career in hadoop technology.
ReplyDeleteRegards,
Hadoop Training in Chennai|Best hadoop training institute in chennai|Big Data Training
I agree with your thoughts!!! As the demand of java programming application keeps on increasing, there is massive demand for java professionals in software development industries. Thus, taking training will assist students to be skilled java developers in leading MNCs.
ReplyDeleteSalesforce Training in Chennai|cloud computing training in chennai|SEO Training in Chennai
Opportunities in PEGA are increasing day by day. This is a future of technology and it has immense scope. Start your career as PEGA developer.
ReplyDeletePEGA Training center in Chennai | PEGA Training Chennai | PEGA Training institutes in Chennai
unix training in chennai
ReplyDeleteThanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeleteBest hadoop training institute in chennai|Hadoop Training Chennai|Hadoop Training in Chennai
Nice Post! It is really interesting to read from the beginning & I would like to share your blog to my circles, keep your blog as updated.
ReplyDeleteRegards,
cloud computing training in chennai|cloud computing training
Thanks for the sharing about sending form java to php.
ReplyDeleteCloud Computing training institute in Gurgaon | ethical hacking training in Gurgaon
Nice and good article.. it is very useful for me to learn and understand easily.. thanks for sharing your valuable information and time.. please keep updating.more php jobs in hyderabad.
ReplyDeleteNice Article. This article is very useful for me.
ReplyDeletesap training institute in gurgaon
Great article. Glad to find your blog. Thanks for sharing.
ReplyDeletesap training institute
its a nice post thank you for this post.
ReplyDeleteBest IT Training in Bangalore
Thank you for post.its a nice post.
ReplyDeleteBest SAP Training in Bangalore
Best Java Training in Bangalore
Its a nice post.
ReplyDeleteBest Oracle Training in Bangalore
Informative blog and it was up to the point describing the information very effectively. Thanks to blog author for wonderful and informative post...
ReplyDeleteAndroid application developers Chennai | Android application developers India