I use java to send a fax via the RingCentral Fax API. However I got HTTP 415 error code. I really have no idea how to make it work.
public void sendFax(String body, String...toList) { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(baseUrl + URI_FAX); httpPost.addHeader("Content-Type", "multipart/mixed; boundary=Boundary_1_6506429161_101"); httpPost.addHeader("Authorization", "Bearer " + rcoAuthResp.getAccess_token()); try { List < RCPhone > list = new ArrayList < > (); for (String to: toList) { list.add(RCPhone.builder().phoneNumber(to).build()); } String requestBody = mapper.writeValueAsString(RCFaxPayload.builder().to(list).faxResolution("High").build()); FormBodyPart bodyPart1 = FormBodyPartBuilder.create() .setName("json") .setBody(new StringBody(requestBody, ContentType.APPLICATION_JSON)) .build(); bodyPart1.getHeader().removeFields("Content-Disposition"); bodyPart1.getHeader().removeFields("Content-Transfer-Encoding"); bodyPart1.getHeader().removeFields("Content-type"); bodyPart1.addField("Content-type", "application/json"); FormBodyPart bodyPart2 = FormBodyPartBuilder.create() .setName("body") .setBody(new StringBody(body, ContentType.TEXT_PLAIN)) .build(); bodyPart2.getHeader().removeFields("Content-Disposition"); bodyPart2.getHeader().removeFields("Content-Transfer-Encoding"); bodyPart2.getHeader().removeFields("Content-type"); bodyPart2.addField("Content-type", "text/plain"); HttpEntity entity = MultipartEntityBuilder .create() .setBoundary("Boundary_1_6506429161_101") .addPart(bodyPart1) .addPart(bodyPart2) .build(); httpPost.setEntity(entity); httpPost.getEntity().writeTo(System.out); String response = processHttpResp(httpClient, httpPost); System.out.println(response); } catch (Exception e) { log.error(e.getMessage(), e); } }