简体   繁体   English

如何将数据从Web发送到Linux服务器

[英]How to send data from web to linux server

I need to send data from my web interface to linux server. 我需要将数据从Web界面发送到linux服务器。 I am using tomcat as server. 我正在使用tomcat作为服务器。 I am new to java, i visited many questions but didn't find any exact solution. 我是Java的新手,我访问了许多问题,但没有找到确切的解决方案。 Other than code i would like to see help regarding process/logic to send data on linux server. 除了代码之外,我还想查看有关在Linux服务器上发送数据的进程/逻辑的帮助。 Manual i post data on server like this, that i need to post by web interface throuhg HTTP. 手册我将这样的数据发布到服务器上,我需要通过HTTP通过Web界面发布数据。

curl --header "Content-type: application/json" --request POST --data '{"name":"John", "id":"500", "employee":"yes","salary":"5000","dept":"accounts"}' http://serverNumericURL.com curl --header“内容类型:application / json”-请求POST --data'{“ name”:“ John”,“ id”:“ 500”,“ employee”:“是”,“薪水”: “ 5000”,“部门”:“帐户”}' http://serverNumericURL.com

I'd recommend using a library like apache http components 我建议使用像Apache HTTP Components这样的库

Example: 例:

CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://serverNumericURL.com");
httpPost.setEntity(new StringRequestEntity(jsonString, "application/json", "UTF-8"));
httpClient.executeMethod(httpPost);

Or if you would like to stick to the JDK, you could use the HTTPURLConnection as in the following link which covers both HTTP GET and POST. 或者,如果您想坚持使用JDK,则可以使用HTTPURLConnection,如以下包含HTTP GET和POST的链接所示。

http://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/ http://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM