繁体   English   中英

BAD 请求 400 使用多部分/表单数据球衣客户端响应 java

[英]BAD Request 400 consume multipart/form-data jersey clientresponse java

我需要消费一个服务,文件是一个excel。 但是当我执行消耗时,响应是“返回了 400 错误请求的响应状态”

String authString = name + ":" + password;
Client restClient = Client.create();
String authStringEnc = Base64.getEncoder().encodeToString(authString.getBytes());
// the file to upload, represented as FileDataBodyPart
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file", new File(file),
        MediaType.APPLICATION_OCTET_STREAM_TYPE);
// fileDataBodyPart.setContentDisposition(FormDataContentDisposition.name("file").fileName(file).build());

FormDataMultiPart multiPart = new FormDataMultiPart();
multiPart.field("spId", idServicio, MediaType.MULTIPART_FORM_DATA_TYPE).bodyPart(fileDataBodyPart);
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

WebResource webResource = restClient.resource(url);
ClientResponse resp = webResource.header("Authorization", "Basic " + authStringEnc)
        .header("Content-Type", "multipart/form-data").post(ClientResponse.class, multiPart);

String output = resp.getEntity(String.class);
System.out.print(output);
return resp;

我放了一个代理,我使用 Rest 客户端“失眠”,它通过失眠对我有用。 这是发送它的请求:

  1. 失眠

    POST /conf/configuration/distribution-files/service HTTP/1.1 Authorization: Basic aW1wbGluZWE6SU1QTElORUE= User-Agent: insomnia/7.0.6 Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY Accept: */* Content-Length: 5872 Connection: close --X-INSOMNIA-BOUNDARY Content-Disposition: form-data; name="file"; filename="myspprueba.xls" Content-Type: application/vnd.ms-excel --X-INSOMNIA-BOUNDARY Content-Disposition: form-data; name="spId" 5823
  2. 这是目前我失败的请求

    POST /conf/configuration/distribution-files/service HTTP/1.1 Authorization: Basic aW1wbGluZWE6SU1QTElORUE= Accept: */* Content-Type: multipart/form-data; boundary=Boundary_1_2104028992_1577117786190 MIME-Version: 1.0 User-Agent: Java/1.8.0_211 Connection: close Content-Length: 5994 --Boundary_1_2104028992_1577117786190 Content-Type: text/plain Content-Disposition: form-data; filename="myspprueba.xls"; modification-date="Thu, 19 Dec 2019 15:52:46 GMT"; size=5632; name="file"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM