简体   繁体   中英

Error posting files with RequestBuilder, 403 Forbidden cloudflare

I'm trying to make a request to send an mp3 file via HttpUriRequest multipartRequest, I've added all the headers that the API documentation asks for (Content-Type multipart/form-data). However, a strange thing I noticed was the "Host" header, when I make a request in Postman, it goes successfully, but when I request my implementation, I get the following error:

400 Bad Request - cloudflare

My code:



    

  CloseableHttpClient httpclient = HttpClients.createDefault();

      MultipartEntityBuilder entitybuilder = MultipartEntityBuilder.create();

      entitybuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

      entitybuilder.addBinaryBody("file", new File("/C:/64551f6c78bc742885a2f0b8100cb039- 
      recording.mp3"));

      HttpEntity mutiPartHttpEntity = entitybuilder.build();

      
      RequestBuilder reqbuilder = 
      RequestBuilder.post("https://api.pipedrive.com/v1/callLogs/"+idActive+"/recordings? 
      api_token=a09e26295e89cb2ccc89b676358deae384046449");
     
      reqbuilder.setEntity(mutiPartHttpEntity);
      reqbuilder.addHeader("Content-Type", "multipart/form-data");
      reqbuilder.addHeader("Accept", "*/*");
      reqbuilder.addHeader("Accept-Encoding", "gzip, deflate, br");
      reqbuilder.addHeader("Connection", "keep-alive");
      reqbuilder.addHeader("Host", "http://localhost:8080/attach");
      
      //Building the request
      HttpUriRequest multipartRequest = reqbuilder.build();
      multipartRequest.addHeader("Content-Type", "multipart/form-data");

      HttpResponse httpresponse = httpclient.execute(multipartRequest);

      System.out.println(EntityUtils.toString(httpresponse.getEntity()));
      System.out.println(httpresponse.getStatusLine());



If anyone has been through this, any help will be of great value.

您在构建请求后添加"multipart/form-data" ,将其向上移动一行

我把这条线放好但我仍然得到一个错误,有一个错误,在构建 RequestBuilder reqbuilder 之前的部分我已经添加了所有的标题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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