How to facilitate communication between php script on a server to a running Java application on another server?

喜你入骨 提交于 2019-12-02 04:10:39

问题


How to establish a way for Java application to listen to data being sent by php ? Sockets or Http POST ?

Essentially, I have Java application running on another server waiting for certain string data sent by PHP script running on other server.

Any library suggestions or example codes will be appreciated.


回答1:


Your best bet is probably going to be to set up a java servlet "container" (server), such as tomcat (you can pay a lot of money for something else, if you have to for corporate reasons).

http://tomcat.apache.org/

http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#getReader() or http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#getInputStream()

Be aware there is a bit of work up front, just to set up and host "hello.jsp", but adding the mapping for the "myservice" servlet in web.xml is not too bad.




回答2:


I suggest implementing a REST api. If you can't or don't want to, using sockets is the most secure way...

If you are sending FROM php, I recommend using a RESTful API with authentication. Send JSON data, get JSON data back. It allows for better future expansion too.



来源:https://stackoverflow.com/questions/4551113/how-to-facilitate-communication-between-php-script-on-a-server-to-a-running-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!