为了账号安全,请及时绑定邮箱和手机立即绑定

Java 9 Httpclient模拟文件上传时如何设置name?

Java 9 Httpclient模拟文件上传时如何设置name?

尚方宝剑之说 2019-03-01 10:29:00
比如我们有这么一个表单: <form action="/example/html5/demo_form.asp" method="post" enctype=”multipart/form-data”> <input type="file" name="img" /> <input type="text" name=username" value="foo"/> <input type="submit" /> </form> 我想使用Java9的Httpclient模拟其提交,代码如下: HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest. newBuilder(new URI("http:///example/html5/demo_form.asp")) .method("post",HttpRequest.BodyProcessor.fromString("foo")) .method("post", HttpRequest.BodyProcessor.fromFile(Paths.get("/path/to/your/file"))) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandler.asString()); System.out.println(response.body()); 不知道如何设置这俩字段的name
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 379 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信