Results 1 to 2 of 2
Thread: HTTP response not read
- 03-10-2009, 04:10 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
HTTP response not read
I have a iPost class that connects to a php script in a remote server, and prints the response message.
When I run the php page in the browser I see output.
When I call the page from within Java class, I get Response OK message and nothing more.
What am I doing wrong?
The response is OK but there string is not retrieved.
Java Code:public String postData(String contents) { String postURL; String responsestr = ""; postURL = "someurl"; BufferedReader bufferedReader = null; StringBuffer sb = new StringBuffer( ); StringBuffer sbResponse = new StringBuffer( ); sb.append( URLEncoder.encode("content") + "=" ); sb.append( URLEncoder.encode(contents)); String formData = sb.toString( ); try { URL url = new URL(postURL); HttpURLConnection urlcon = (HttpURLConnection) url.openConnection(); //Send Post Request urlcon.setRequestMethod("POST"); urlcon.setRequestProperty("Content-type","application/x-www-form-urlencoded"); urlcon.setUseCaches(false) ; urlcon.setDoOutput(true); urlcon.setDoInput(true); PrintWriter pout = new PrintWriter( new OutputStreamWriter( urlcon.getOutputStream( ), "8859_1"), true ); pout.print( formData ); pout.flush(); // read results... if ( urlcon.getResponseCode() == HttpURLConnection.HTTP_OK ){ System.out.println("Posted ok!"); System.out.println("Res" + urlcon.getResponseMessage()); //OK read System.out.println("Size: "+urlcon.getContentLength()); // is 0 System.out.println("RespCode: "+urlcon.getResponseCode()); // is 200 System.out.println("RespMsg: "+urlcon.getResponseMessage()); // is 'OK' } else { System.out.println("Bad post..."); } } catch (Exception e){ System.out.println(e); // bad postURL } return responsestr; }//EO postData
- 03-10-2009, 04:36 PM #2
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
Well, I managed to solve the issue and I thought I would post the solution in case somebody else tries a similar setup.
The database was throwing an exception which strangely was not reported while browsing directly. When the exception in php was handled and the output was started before the function call was made, the issue was resolved.
Similar Threads
-
Server returned HTTP response code: 500.. i need help
By hardc0d3r in forum Java ServletReplies: 9Last Post: 03-12-2012, 08:08 PM -
Server returned HTTP response code: 500
By fuliangQ in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-09-2009, 03:55 AM -
Http Webserver - Mage inclution in response
By nlgopi in forum NetworkingReplies: 3Last Post: 10-18-2008, 03:17 PM -
java.io.Exception: Server returned HTTP response code: 403
By navishkumarb in forum Advanced JavaReplies: 1Last Post: 01-05-2008, 01:33 PM -
Server returned HTTP response code: 500
By Heather in forum Java ServletReplies: 1Last Post: 07-09-2007, 04:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks