gpt4 book ai didi

java - 如何使用curl发送参数?

转载 作者:太空宇宙 更新时间:2023-11-04 13:02:53 24 4
gpt4 key购买 nike

我试图在执行 java spring 项目时添加参数。

案例)Java独立:java -cp target/A.jar myProgram arg1 arg2 arg3 arg4 -> 可以工作!

SPRING-RESTful API 案例怎么样?
没有争论,我使用
curl -H“接受:application/json”-H“X-AUTH-TOKEN:XXXX”-X POST -d“[1234,4567,89012]”http://my.ip.address:port/myProgram

那么,如何在该curl命令中包含arg1、arg2、arg3、arg4?

<小时/>

GreetingController.java

package Rest;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

import java.nio.charset.Charset;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

import myProgram;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;


//
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();

// @Autowired
// bboxevolutionTripleFromDB processor;


@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}


@RequestMapping(value="/myProgram", method = RequestMethod.POST)
public ResponseEntity<String> doDemo(@RequestHeader("X-AUTH-TOKEN") String authToken) {

try {
TypeInferenceMain.doDemo(null);
StringBuffer sb = new StringBuffer("[");

sb.append("]");
HttpHeaders responseHeaders = new HttpHeaders();
MediaType mediaType = new MediaType("application", "json", Charset.forName("UTF-8"));
responseHeaders.setContentType(mediaType);
return new ResponseEntity(sb.toString(), responseHeaders, HttpStatus.OK);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

HttpHeaders responseHeaders = new HttpHeaders();
MediaType mediaType = new MediaType("application", "json", Charset.forName("UTF-8"));
responseHeaders.setContentType(mediaType);

return new ResponseEntity("[]", responseHeaders, HttpStatus.OK);
}

}

最佳答案

我需要更多信息来确定参数使用什么编码类型,但它是这样的:

curl -X POST -H "Accept: application/json" -H "X-AUTH-TOKEN: token" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 88fd44ab-692a-bef0-c80e-fe8b98c33bd1" -d '[arg1][arg2][arg3][arg4]' 'http://my.ip.address:port/myProgram'

关于java - 如何使用curl发送参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34785091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com