CURL与运行时中的空间问题 [英] space issue in CURL with Runtime

查看:123
本文介绍了CURL与运行时中的空间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CURL命令,需要使用JSP文件中的Runtime方法运行

I have a CURL command which need to be run with the Runtime method in a JSP file

int cnt=10;    
String strCount="count"+cnt+"";
String msg= "{'text':'"+strCount+"'}";
String cmd = "curl -X POST -H 'Content-type: application/json' --data "+ msg +" https://hooks.slack.com/services/#####/###/###";
Runtime.getRuntime().exec(cmd);

哪个可以正常工作,但是当我将strCount更改为:

Which works fine, but when I change strCount to:

String strCount="Count is "+cnt+"";

它不再起作用了.很明显,Count is之间的空格不再起作用.

It doesn't work anymore. It's clear that the space between Count is is not working anymore.

推荐答案

将代码更改为此.

Runtime.getRuntime().exec(new String[] {"curl","-X", "POST","-H","'Content-type: application/json'","--data", msg, "https://hooks.slack.com/services/#####/###/###"});

按照

as per the Runtime#exec() docs, you can pass individual arguments with spaces in them if you make them an array, as seen above.

这篇关于CURL与运行时中的空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆