Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.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 JAX-RS 2.0客户端-使用RESTEasy客户端发送多部分消息_Java_Rest_Client_Jax Rs_Resteasy - Fatal编程技术网

Java JAX-RS 2.0客户端-使用RESTEasy客户端发送多部分消息

Java JAX-RS 2.0客户端-使用RESTEasy客户端发送多部分消息,java,rest,client,jax-rs,resteasy,Java,Rest,Client,Jax Rs,Resteasy,我正在使用RESTEasy客户端。 Maven依赖项: <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-client</artifactId> <version>3.0.1.Final</version> </dependency> 现在请帮我输入客户端代码 WebTarget t

我正在使用RESTEasy客户端。
Maven依赖项:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.0.1.Final</version>
</dependency>
现在请帮我输入客户端代码

WebTarget target = client.target("http://localhost:8080").path("path");
//TODO somehow fill multipart
Response response = target.request().put(/*RESTEasy multipart entity or something*/);
response.close();
感谢“lefloh”的评论——我终于做到了

您必须添加这些maven依赖项

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.0.1.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-multipart-provider</artifactId>
    <version>3.0.1.Final</version>
</dependency>

org.jboss.resteasy
resteasy客户端
3.0.1.最终版本
org.jboss.resteasy
resteasy多部分提供程序
3.0.1.最终版本
以下是客户端代码:

ResteasyClient client = (ResteasyClient) this.client;
ResteasyWebTarget target = client.target("http://localhost:8080").path("path");
MultipartFormDataOutput mdo = new MultipartFormDataOutput();
mdo.addFormData("firstPart", new ByteArrayInputStream("firstContent".getBytes()), MediaType.TEXT_PLAIN_TYPE);
mdo.addFormData("secondPart", new ByteArrayInputStream("secondContent".getBytes()), MediaType.TEXT_PLAIN_TYPE);
GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(mdo) { };
Response response = target.request().put(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));
response.close();
ResteasyClient客户端=(ResteasyClient)this.client;
ResteasyWebTarget=client.target(“http://localhost:8080)路径(“路径”);
MultipartFormDataOutput mdo=新的MultipartFormDataOutput();
mdo.addFormData(“firstPart”,新的ByteArrayInputStream(“firstContent.getBytes()),MediaType.TEXT\u PLAIN\u TYPE);
mdo.addFormData(“secondPart”、new ByteArrayInputStream(“secondContent.getBytes())、MediaType.TEXT\u PLAIN\u TYPE);
GenericeEntity实体=新的GenericeEntity(mdo){};
Response Response=target.request().put(Entity.Entity(Entity,MediaType.MULTIPART_FORM_DATA_TYPE));
response.close();

to可能会有所帮助。您好,有没有办法不依赖JAX-RS 2.0的特定实现来实现这一点?我需要发展一个类似的客户群,但与他们中的任何一个都没有联系。MultipartFormDataOutput特定于RESTEasy。谢谢。没有。据我所知。JAX-RS规范不包括多部分。
ResteasyClient client = (ResteasyClient) this.client;
ResteasyWebTarget target = client.target("http://localhost:8080").path("path");
MultipartFormDataOutput mdo = new MultipartFormDataOutput();
mdo.addFormData("firstPart", new ByteArrayInputStream("firstContent".getBytes()), MediaType.TEXT_PLAIN_TYPE);
mdo.addFormData("secondPart", new ByteArrayInputStream("secondContent".getBytes()), MediaType.TEXT_PLAIN_TYPE);
GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(mdo) { };
Response response = target.request().put(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));
response.close();