Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误请求400使用多部分/表单数据jersey clientresponse java_Java_Http_Jersey_Multipartform Data_Bad Request - Fatal编程技术网

错误请求400使用多部分/表单数据jersey clientresponse java

错误请求400使用多部分/表单数据jersey clientresponse java,java,http,jersey,multipartform-data,bad-request,Java,Http,Jersey,Multipartform Data,Bad Request,我需要使用一个服务,该文件是一个excel。 但当我执行consume时,响应是“返回了400个错误请求的响应状态” 我放置了一个代理,使用Rest客户机“失眠”,失眠对我有效。 这是发送它的请求: 失眠 POST/conf/configuration/distribution files/service HTTP/1.1 授权:基本AW1WBGLUZWE6SU1QTELOUE= 用户代理:失眠/7.0.6 内容类型:多部分/表单数据;边界=X-边界 接受:*/* 内容长度:5872 连接:关闭

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


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

  • 失眠

    POST/conf/configuration/distribution files/service HTTP/1.1
    授权:基本AW1WBGLUZWE6SU1QTELOUE=
    用户代理:失眠/7.0.6
    内容类型:多部分/表单数据;边界=X-边界
    接受:*/*
    内容长度:5872
    连接:关闭
    --X-边界
    内容配置:表单数据;name=“file”;filename=“mysprueba.xls”
    内容类型:application/vnd.ms-excel
    --X-边界
    内容配置:表单数据;name=“spId”
    5823
    
  • 这是目前我未能满足的要求

    POST/conf/configuration/distribution files/service HTTP/1.1
    授权:基本AW1WBGLUZWE6SU1QTELOUE=
    接受:*/*
    内容类型:多部分/表单数据;边界=边界_1_2104028992_1577117786190
    MIME版本:1.0
    用户代理:Java/1.8.0_211
    连接:关闭
    内容长度:5994
    --边界1_2104028992_1577117786190
    内容类型:文本/纯文本
    内容配置:表单数据;filename=“mysprueba.xls”;修改日期=“2019年12月19日星期四15:52:46 GMT”;尺寸=5632;name=“文件”
    

  • 检查请求正文(如果您正在向服务器发送所有必需的输入)。使用Rest客户端,如Postman或Chrome ARC,查看您是否从服务中获得了任何回报。400错误的请求可能是因为您没有发送正确的请求正文。也可能是您发送的字符集无法理解,因此您可以添加.header(“内容类型”,“多部分/表单数据;;charset=UTF-8”)。我放置了一个代理,使用Rest客户端“失眠”,失眠对我有效。我看到的都一样。我把双方的要求都打了出来。谢谢你的帮助,我解决不了这个错误。我使用了其他客户端,apache Httpcomponents。谢谢你的帮助。
    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;