Tag: curl

curl POST没有传递URL参数

这是我的java代码: @POST @Path(“/sumPost”) @Produces(MediaType.TEXT_PLAIN) public String sumPost(@QueryParam(value = “x”) int x, @QueryParam(value = “y”) int y) { System.out.println(“x = ” + x); System.out.println(“y = ” + y); return (x + y) + “\n”; } 我称之为: curl -XPOST “http://localhost:8080/CurlServer/curl/curltutorial/sumPost” -d ‘x:5&y:3’ 问题是System.out.println调用保持零零,似乎我没有正确传递x和y。 更新 在答案之后,我将我的请求更改为: curl -d ‘{“x” : 4, “y”:3}’ “http://localhost:8080/CurlServer/curl/curltutorial/sumPost” -H “Content-Type:application/json” -H “Accept:text/plain” –include […]

将CURL请求转换为HTTP请求Java

我有以下CURL请求任何人都可以请确认我的subesquest HTTP请求 curl -u “Login-dummy:password-dummy” -H “X-Requested-With: Curl” “https://qualysapi.qualys.eu/api/2.0/fo/report/?action=list” -k 它会是什么样的? String url = “https://qualysapi.qualys.eu/api/2.0/fo/report/”; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // optional default is GET con.setRequestMethod(“GET”); ….. //incomplete 任何人都可以帮助我完全将上述curl请求转换为httpreq。 提前致谢。 苏维

cURL和HttpURLConnection – 发布JSON数据

如何使用HttpURLConnection发布JSON数据? 我正在尝试这个: HttpURLConnection httpcon = (HttpURLConnection) ((new URL(“a url”).openConnection())); httpcon.setDoOutput(true); httpcon.setRequestProperty(“Content-Type”, “application/json”); httpcon.setRequestProperty(“Accept”, “application/json”); httpcon.setRequestMethod(“POST”); httpcon.connect(); StringReader reader = new StringReader(“{‘value’: 7.5}”); OutputStream os = httpcon.getOutputStream(); char[] buffer = new char[4096]; int bytes_read; while((bytes_read = reader.read(buffer)) != -1) { os.write(buffer, 0, bytes_read);// I am getting compilation error here } os.close(); 我在第14行遇到编译错误。 cURL请求是: curl -H “Accept: […]

在java中使用curl命令

我有一个curl命令可以使用 curl -s -d user.name=xxxx \ -d file=yyyy \ -d arg=-v \ ‘http://localhost:zzzz/templeton/v1/pig’ 任何人都可以为上面的curl命令告诉等效的java代码。 提前致谢