用 resteasy 提出请求
Put request with resteasy
我想使用类似于以下 curl 命令的 resteasy 构造一个放置请求:
curl -u myUser:myP455w0rd! -X PUT "http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt" -T Desktop/myNewFile.txt
我从类似
的东西开始
Client client = ClientBuilder.newClient();
ResteasyWebTarget rWebTarget = (ResteasyWebTarget) client.target(targetPath);
rWebTarget.register(new BasicAuthentication(user, password));
rWebTarget.request().put(entity);
我想我必须将本地文件指定为 entity
,但我不清楚该怎么做。
它似乎按以下方式工作:
Client client = ClientBuilder.newClient();
ResteasyWebTarget rWebTarget = (ResteasyWebTarget) client.target(targetPath);
rWebTarget.register(new BasicAuthentication(user, password));
InputStream stream = Files.newInputStream(path);
Entity<InputStream> entity = Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM);
Response put = rWebTarget.request().put(entity);
我想使用类似于以下 curl 命令的 resteasy 构造一个放置请求:
curl -u myUser:myP455w0rd! -X PUT "http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt" -T Desktop/myNewFile.txt
我从类似
的东西开始Client client = ClientBuilder.newClient();
ResteasyWebTarget rWebTarget = (ResteasyWebTarget) client.target(targetPath);
rWebTarget.register(new BasicAuthentication(user, password));
rWebTarget.request().put(entity);
我想我必须将本地文件指定为 entity
,但我不清楚该怎么做。
它似乎按以下方式工作:
Client client = ClientBuilder.newClient();
ResteasyWebTarget rWebTarget = (ResteasyWebTarget) client.target(targetPath);
rWebTarget.register(new BasicAuthentication(user, password));
InputStream stream = Files.newInputStream(path);
Entity<InputStream> entity = Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM);
Response put = rWebTarget.request().put(entity);