Avatar of HLRosenberger
HLRosenberger
Flag for United States of America asked on

Need help with HTTP Post/Get in an applet/servlet environment

I heed help with HTTP POST/GET in a client/servlet environment.  I want to write a Java client and servlet.  They will communicate via HTTP to POST/GET XML documents.  

This is using Apache Tomcat on the server side.

I have the start a client and servlet code.  My client applet can connect to the my server using this string:  ("http://localhost:8080/IPCServer");

IPCServer is the name of my servlet.  By using my browser and entering the connection string, I get a response from my servlet - it puts out some HTML to the browser.  However, I can't get my servlet to respond to my client applet.  Below is the code in my applet.  What am I doing wrong?  

            urlConn.setUseCaches(false);
            urlConn.setAllowUserInteraction(false);

            //urlConn.setRequestProperty("User-Agent", "BlackBerry");
            //urlConn.setRequestProperty("Accept_Language","en-US");

            //Content-Type is must to pass parameters in POST Request
            //urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            urlConn.setRequestProperty("Content-Type", "text/xml");
            urlConn.setRequestMethod("POST");

            String testData = URLEncoder.encode("This is my test data", "UTF-8");

            OutputStreamWriter out = new OutputStreamWriter(urlConn.getOutputStream());

            out.write("string=" + testData);
            out.flush();
            out.close();
Java App ServersFile Sharing SoftwareJava EE

Avatar of undefined
Last Comment
girionis

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Mick Barry

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
girionis

Another solution is to just use the HttpComponents, from the apache foundation, and use the HttpPost/HttpGet classes

http://hc.apache.org/downloads.cgi
http://hc.apache.org/httpcomponents-client/tutorial/html/fundamentals.html (for a tutorial)
Your help has saved me hundreds of hours of internet surfing.
fblack61