Results 1 to 2 of 2
  1. #1
    SD_Be is offline Member
    Join Date
    Mar 2009
    Rep Power

    Default 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.setUseCaches(false) ;
    		    	PrintWriter pout = new PrintWriter( new OutputStreamWriter(
    		    	urlcon.getOutputStream(  ), "8859_1"), true );
    		    	pout.print( formData );
    		    	// 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

  2. #2
    SD_Be is offline Member
    Join Date
    Mar 2009
    Rep Power


    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

  1. Server returned HTTP response code: 500.. i need help
    By hardc0d3r in forum Java Servlet
    Replies: 9
    Last Post: 03-12-2012, 08:08 PM
  2. Server returned HTTP response code: 500
    By fuliangQ in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-09-2009, 03:55 AM
  3. Http Webserver - Mage inclution in response
    By nlgopi in forum Networking
    Replies: 3
    Last Post: 10-18-2008, 03:17 PM
  4. Server returned HTTP response code: 403
    By navishkumarb in forum Advanced Java
    Replies: 1
    Last Post: 01-05-2008, 01:33 PM
  5. Server returned HTTP response code: 500
    By Heather in forum Java Servlet
    Replies: 1
    Last Post: 07-09-2007, 04:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts