Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Android
URLConnection to Servlet
Susan Fahem
Greenhorn
Posts: 1
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I know that this post seem repeated, but I tried
alot
befor posting.
I have an android application that I want to make it connect to a
servlet
through a URLConnection. but when I send the data I want, I just recive nothing on the servlet.
the android part
String link ="http://XXX.XXX.XXX.XXX:8080//Parse"; String params = userNameString+';'+passWordString; byte[] bytes = params.getBytes("UTF-8"); URL url = new URL(link); HttpURLConnection urlconn = (HttpURLConnection) url.openConnection(); urlconn.setRequestProperty("Content-Type", "text/xml"); urlconn.setRequestProperty("Content-Length", String.valueOf(bytes.length)); urlconn.setRequestMethod("POST"); urlconn.setDoOutput(true); urlconn.setChunkedStreamingMode(0); urlconn.connect(); DataOutputStream os = new DataOutputStream(urlconn.getOutputStream()); os.writeBytes(params); os.flush(); os.close();
and the servlet part is
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println ("inpost"); BufferedReader reader = new BufferedReader( new InputStreamReader(request.getInputStream() ) ); String res = reader.readLine(); while( null != res ) { System.out.println( res ); res = reader.readLine(); } /*InputStream is = new BufferedInputStream(request.getInputStream()); byte[] buf = new byte[8096]; int bytesRead; System.out.println("readbuf "+ is.read( buf )); while( ( bytesRead = is.read( buf ) ) != -1 ) os.write( buf, 0, bytesRead ); */ }
anybody urgently help?
Hardik Trivedi
Ranch Hand
Posts: 252
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Does your servlet print that 'inpost' ?
R Hoefer
Greenhorn
Posts: 10
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
See if this helps.
http://stackoverflow.com/questions/4844535/why-do-you-have-to-call-urlconnectiongetinputstream-to-be-able-to-write-out-to
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
com.oreilly.servlet package!
Call the action class from Applet
Urgent !
help: need help for post
how to copy files form server to local path?
More...