@Test public void getRequestPostData() throws Exception { List<NameValuePair> pairs = new ArrayList<>(); String contentType = "multipart/mixed; boundary=ABCDEF_1522096137171"; String postDataText = "--ABCDEF_1522096137171\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" + "\r\n" + "foo=bar&baz=gaw\r\n" + "--ABCDEF_1522096137171--"; String postDataComment = ""; Long requestBodySize = 116L; ByteSource actual = Hars.getRequestPostData(pairs, contentType, postDataText, requestBodySize, postDataComment, UTF_8); assertNotNull("byte source not null is expected", actual); ByteSource expected = CharSource.wrap(postDataText).asByteSource(StandardCharsets.US_ASCII); assertEquals("bytes", BaseEncoding.base16().encode(expected.read()), BaseEncoding.base16().encode(actual.read())); }
@Nullable public static ByteSource getRequestPostData(@Nullable List<NameValuePair> params, String contentType, String postDataText, @Nullable Long requestBodySize, @Nullable String postDataComment, Charset defaultCharset) throws IOException { if (params != null && !params.isEmpty()) { if (Strings.isNullOrEmpty(contentType)) { contentType = MediaType.FORM_DATA.toString(); } MediaType mediaType = MediaType.parse(contentType); return toByteSourceFromPairs(params, mediaType); } else { return translateRequestContent(contentType, postDataText, requestBodySize, null, postDataComment, defaultCharset); } }
Hars { @Nullable public static ByteSource getRequestPostData(@Nullable List<NameValuePair> params, String contentType, String postDataText, @Nullable Long requestBodySize, @Nullable String postDataComment, Charset defaultCharset) throws IOException { if (params != null && !params.isEmpty()) { if (Strings.isNullOrEmpty(contentType)) { contentType = MediaType.FORM_DATA.toString(); } MediaType mediaType = MediaType.parse(contentType); return toByteSourceFromPairs(params, mediaType); } else { return translateRequestContent(contentType, postDataText, requestBodySize, null, postDataComment, defaultCharset); } } }
Hars { @Nullable public static ByteSource getRequestPostData(@Nullable List<NameValuePair> params, String contentType, String postDataText, @Nullable Long requestBodySize, @Nullable String postDataComment, Charset defaultCharset) throws IOException { if (params != null && !params.isEmpty()) { if (Strings.isNullOrEmpty(contentType)) { contentType = MediaType.FORM_DATA.toString(); } MediaType mediaType = MediaType.parse(contentType); return toByteSourceFromPairs(params, mediaType); } else { return translateRequestContent(contentType, postDataText, requestBodySize, null, postDataComment, defaultCharset); } }  }
Hars { @Nullable public static ByteSource getRequestPostData(@Nullable List<NameValuePair> params, String contentType, String postDataText, @Nullable Long requestBodySize, @Nullable String postDataComment, Charset defaultCharset) throws IOException { if (params != null && !params.isEmpty()) { if (Strings.isNullOrEmpty(contentType)) { contentType = MediaType.FORM_DATA.toString(); } MediaType mediaType = MediaType.parse(contentType); return toByteSourceFromPairs(params, mediaType); } else { return translateRequestContent(contentType, postDataText, requestBodySize, null, postDataComment, defaultCharset); } }  static boolean isBase64Encoded(String contentType, String text, @Nullable String harContentEncoding, @Nullable Long bodySize); @Nullable static ByteSource getRequestPostData(@Nullable List<NameValuePair> params, String contentType, String postDataText, @Nullable Long requestBodySize, @Nullable String postDataComment, Charset defaultCharset); static TypedContent translateResponseContent(              String contentType,
                                                                      @Nullable String text,
                                                                      @Nullable Long bodySize,
                                                                      @Nullable Long contentSize,
                                                                      @Nullable String contentEncodingHeaderValue,
                                                                      @Nullable String harContentEncoding,
                                                                      @SuppressWarnings("unused") @Nullable String comment,
                                                                      Charset defaultCharset); static HarHeader newHarHeader(String name, String value); }
Hars { @Nullable public static ByteSource getRequestPostData(@Nullable List<NameValuePair> params, String contentType, String postDataText, @Nullable Long requestBodySize, @Nullable String postDataComment, Charset defaultCharset) throws IOException { if (params != null && !params.isEmpty()) { if (Strings.isNullOrEmpty(contentType)) { contentType = MediaType.FORM_DATA.toString(); } MediaType mediaType = MediaType.parse(contentType); return toByteSourceFromPairs(params, mediaType); } else { return translateRequestContent(contentType, postDataText, requestBodySize, null, postDataComment, defaultCharset); } }  static boolean isBase64Encoded(String contentType, String text, @Nullable String harContentEncoding, @Nullable Long bodySize); @Nullable static ByteSource getRequestPostData(@Nullable List<NameValuePair> params, String contentType, String postDataText, @Nullable Long requestBodySize, @Nullable String postDataComment, Charset defaultCharset); static TypedContent translateResponseContent(              String contentType,
                                                                      @Nullable String text,
                                                                      @Nullable Long bodySize,
                                                                      @Nullable Long contentSize,
                                                                      @Nullable String contentEncodingHeaderValue,
                                                                      @Nullable String harContentEncoding,
                                                                      @SuppressWarnings("unused") @Nullable String comment,
                                                                      Charset defaultCharset); static HarHeader newHarHeader(String name, String value);  }