Send data to 3rd party server using Java

Posted on 2012-09-18
Last Modified: 2012-11-19
I am trying to send data from one server to another using Java program. But I dont want the data to show in the URL, so far I got

    String inputFromPage =  null;
    String inputFromPageStrXKey = this.getParameter("strXKey");
    String inputFromPageStrName = this.getParameter("strName");

    if (inputFromPage == null) inputFromPage = defaultMessage;
    if (inputFromPageStrXKey == null) inputFromPage = defaultMessage;
    if (inputFromPageStrName == null) inputFromPage = defaultMessage;
    g.drawString(inputFromPageStrXKey, 25, 10);
    g.drawString(inputFromPageStrName, 25, 25);
	URL url = null;
	String line = "VALUES:";

	try {

		String data = URLEncoder.encode("StrXKey", "UTF-8") + "=" + URLEncoder.encode(inputFromPageStrXKey, "UTF-8");
		data += "&" + URLEncoder.encode("StrName", "UTF-8") + "=" + URLEncoder.encode(inputFromPageStrName, "UTF-8");
		url = new URL("" + "?" + data);
		URLConnection conn = url.openConnection();
		OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
		wr.write("string=" + data);

		// Get the response
		//BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			g.drawString(inputFromPageStrName, 25, 55);
InputStream in = conn.getInputStream(); 
String encoding = conn.getContentEncoding(); 
encoding = encoding == null ? "UTF-8" : encoding; 

    	//read it with BufferedReader
    	BufferedReader br
        	= new BufferedReader(
        		new InputStreamReader(in));
    	StringBuilder sb = new StringBuilder();
    	String line2;
    	while ((line2 = br.readLine()) != null) {
			g.drawString(sb.toString(), 25, 115);
	} catch (Exception e) {
			g.drawString("FAILED", 25, 70);

Open in new window

This works, but it adds the data to the end of the url string.
I dont want that, I want the data sent so no-one can see the data in the url string.

Can anyone help?
Question by:dipster307
    LVL 81

    Expert Comment

    LVL 20

    Accepted Solution

    Use POST method.

    Agree with leakim971. Use the link provided by him.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now