如何使用 Java WS/RS 注释将文件 "fake" 发送到 Web 服务?
How can I "fake" a file to a web service using Java WS/RS annotations?
我正在尝试 post 到网络服务。我使用的是带注释的界面,然后是在 Spring 中配置的 CXF jaxrs:client。该服务需要用户名、密码和一个文件,因此可以正常工作:
@POST
@Path("/upload")
@Consumes("multipart/form-data")
String uploadFile(
@QueryParam("username") String username,
@QueryParam("password") String password,
@Multipart() File file
);
但有时我想使用该服务,但我没有将文件作为磁盘上的文件,只有字符串,而且我无法写入临时文件。所以我正在寻找将产生完全相同的 post 但来自字符串的注释。这不起作用:
@POST
@Path("/upload")
@Consumes("multipart/form-data")
String uploadFile(
@QueryParam("username") String username,
@QueryParam("password") String password,
@Multipart() String file
);
有没有正确的方法可以使用注释来做到这一点?
@Multipart File
功能很方便。你不必使用它。您可以在下一级操作。一方面,它可能适用于 InputStream。参见 the documentation,特别是在 'Uploading files with Client API'.
下
我正在尝试 post 到网络服务。我使用的是带注释的界面,然后是在 Spring 中配置的 CXF jaxrs:client。该服务需要用户名、密码和一个文件,因此可以正常工作:
@POST
@Path("/upload")
@Consumes("multipart/form-data")
String uploadFile(
@QueryParam("username") String username,
@QueryParam("password") String password,
@Multipart() File file
);
但有时我想使用该服务,但我没有将文件作为磁盘上的文件,只有字符串,而且我无法写入临时文件。所以我正在寻找将产生完全相同的 post 但来自字符串的注释。这不起作用:
@POST
@Path("/upload")
@Consumes("multipart/form-data")
String uploadFile(
@QueryParam("username") String username,
@QueryParam("password") String password,
@Multipart() String file
);
有没有正确的方法可以使用注释来做到这一点?
@Multipart File
功能很方便。你不必使用它。您可以在下一级操作。一方面,它可能适用于 InputStream。参见 the documentation,特别是在 'Uploading files with Client API'.