[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Send data to 3rd party server using Java

Posted on 2012-09-18
2
Medium Priority
?
285 Views
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("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?
0
Comment
Question by:dipster307
2 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 38409101
0
 
LVL 21

Accepted Solution

by:
Amitkumar P earned 1500 total points
ID: 38409462
Use POST method.

Agree with leakim971. Use the link provided by him.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

831 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