Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带有@HeaderParam和List的cxf rest服务HTML客户端_Java_Html_Web Services_Rest - Fatal编程技术网

Java 带有@HeaderParam和List的cxf rest服务HTML客户端

Java 带有@HeaderParam和List的cxf rest服务HTML客户端,java,html,web-services,rest,Java,Html,Web Services,Rest,我有带有@HeaderParam的cxf rest服务,并将附件列为参数。我必须创建html客户端来调用服务。有人能帮我设置headerparams吗?因为当我点击服务时,我得到以下异常 java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: value can't be null for parameter param1 由于此参数设置为@NotNull&NotBlank,因此无法在标头中找到。此异常,因为所需标头不能作为H

我有带有@HeaderParam的cxf rest服务,并将附件列为参数。我必须创建html客户端来调用服务。有人能帮我设置headerparams吗?因为当我点击服务时,我得到以下异常

java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: value can't be null for parameter param1

由于此参数设置为@NotNull&NotBlank,因此无法在标头中找到。

此异常,因为所需标头不能作为HttpRequest标头的一部分使用

您必须编写代码来设置自定义标头。类似于下面的代码,这样您的REST资源将使用传入请求头中的参数

HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("Your URL");

//Adding custom headers
request.addHeader("HEADER_NAME", "VALUE");
HttpResponse response = client.execute(request);

System.out.println("Http Response Code : " 
            + response.getStatusLine().getStatusCode());

BufferedReader reader = new BufferedReader(
    new InputStreamReader(response.getEntity().getContent()));

StringBuffer result = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
    result.append(line);
}

谢谢@Gnana,我已经在main方法中写了这个,它的工作非常好,但是我需要使用HTML作为客户端,所以任何其他的建议都是如此。如果它是一个普通的HTML,你可以使用HTML元标记。但若你们想以一种动态的方式来做这件事,你们可以使用AJAX请求。你们能提供一些例子吗?我试着添加标题,但并没有成功。