Send data to 3rd party server using Java

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("http://jargonfreepartners.co.uk/default.aspx" + "?" + data);
		
		URLConnection conn = url.openConnection();
		conn.setDoOutput(true);
		OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
		wr.write("string=" + data);
		wr.flush();

		// Get the response
		//BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			
			g.drawString(inputFromPageStrName, 25, 55);
			
		wr.close();
		
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) {
    		sb.append(line2);
    	} 			
			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?
dipster307Asked:
Who is Participating?
 
Amitkumar PSr. ConsultantCommented:
Use POST method.

Agree with leakim971. Use the link provided by him.
0
 
leakim971PluritechnicianCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.