gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:12:42 24 4
gpt4 key购买 nike

我需要使用一个服务,文件是一个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 客户端“insomnia”,它对我的​​ insomnia 有效。这是发送它的请求:

  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"

关于java - BAD 请求 400 使用多部分/表单数据泽西客户端响应 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59457983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com