java - Unable to receive JSON POST request in PHP -


i passing josn object java php. using jdk 1.8 ang wamp server. below java code.

import java.io.ioexception; import org.apache.http.client.methods.httppost; import org.apache.http.entity.stringentity; import org.apache.http.impl.client.closeablehttpclient; import org.apache.http.impl.client.httpclientbuilder; import org.json.simple.jsonobject;  /**  *  * @author preeet dash  */ public class fromjava  {     public static void main(string[] args) throws ioexception     {         jsonobject json = new jsonobject();         json.put("somekey", "somevalue");              closeablehttpclient httpclient = httpclientbuilder.create().build();          try          {             httppost request = new httppost("http://localhost/pgp/jsonreq/tophp.php");             stringentity params = new stringentity(json.tostring());             request.addheader("content-type", "application/json");             request.setentity(params);             httpclient.execute(request);         // handle response here...         } catch (exception ex)          {             system.out.println("error: cannot estabilish connection");                 }                   {             httpclient.close();         }     }     } 

php script:

$data = json_decode(file_get_contents("php://input")); echo($data); 

when run php file shows empty page. can please me understand why not working.

when run following php code executes else condition.

if ($_server['request_method'] == 'post')     {         $data = json_decode(file_get_contents("php://input"));         echo($data);     }     else     {         echo "xxxxxx";     }  

i not think work.

a php script not "listening" webservice. however, upon receiving request, script processes , try "print" result in html, not java.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -