@Test public void getRequestPostData_params() throws Exception { String json = "{\n" + " \"method\": \"POST\",\n" + " \"url\": \"https: " \"httpVersion\": \"HTTP/1.1\",\n" + " \"headers\": [\n" + " {\n" + " \"name\": \"Host\",\n" + " \"value\": \"www.example.com\"\n" + " },\n" + " {\n" + " \"name\": \"Connection\",\n" + " \"value\": \"keep-alive\"\n" + " },\n" + " {\n" + " \"name\": \"User-Agent\",\n" + " \"value\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36\"\n" + " },\n" + " {\n" + " \"name\": \"content-type\",\n" + " \"value\": \"application/x-www-form-urlencoded;charset\\u003dUTF-8\"\n" + " }\n" + " ],\n" + " \"queryString\": [\n" + " {\n" + " \"name\": \"csrfToken\",\n" + " \"value\": \"ajax:123456789034567890\"\n" + " }\n" + " ],\n" + " \"postData\": {\n" + " \"mimeType\": \"application/x-www-form-urlencoded;charset\\u003dUTF-8\",\n" + " \"params\": [\n" + " {\n" + " \"name\": \"plist\",\n" + " \"value\": \"eeny/meeny/miny/mo\",\n" + " \"comment\": \"\"\n" + " }\n" + " ],\n" + " \"comment\": \"\"\n" + " },\n" + " \"headersSize\": 993,\n" + " \"bodySize\": 1996,\n" + " \"comment\": \"\"\n" + "}"; HarEntry harEntry = new HarEntry(); HarRequest request = new Gson().fromJson(json, HarRequest.class); harEntry.setRequest(request); ByteSource postData = new SstoehrHarBridge().getRequestPostData(harEntry); assertNotNull("post data", postData); HttpEntity entity = makeEntity(postData, MediaType.FORM_DATA.withCharset(UTF_8)); List<NameValuePair> params = URLEncodedUtils.parse(entity); assertEquals("num params", 1, params.size()); NameValuePair param = params.iterator().next(); assertEquals("name", "plist", param.getName()); assertEquals("value", "eeny/meeny/miny/mo", param.getValue()); }
@Nullable @Override public ByteSource getRequestPostData(HarEntry entry) throws IOException { HarRequest request = entry.getRequest(); if (request != null) { HarPostData postData = request.getPostData(); if (postData != null) { List<HarPostDataParam> params = postData.getParams(); List<NameValuePair> pairs = null; if (params != null) { pairs = params.stream().map(p -> NameValuePair.of(p.getName(), p.getValue())).collect(Collectors.toList()); } String contentType = postData.getMimeType(); String postDataText = postData.getText(); @Nullable Long requestBodySize = nullIfNegative(request.getBodySize()); @Nullable String postDataComment = postData.getComment(); return Hars.getRequestPostData(pairs, contentType, postDataText, requestBodySize, postDataComment, exMachinaCharset); } } return null; }
SstoehrHarBridge implements HarBridge<HarEntry> { @Nullable @Override public ByteSource getRequestPostData(HarEntry entry) throws IOException { HarRequest request = entry.getRequest(); if (request != null) { HarPostData postData = request.getPostData(); if (postData != null) { List<HarPostDataParam> params = postData.getParams(); List<NameValuePair> pairs = null; if (params != null) { pairs = params.stream().map(p -> NameValuePair.of(p.getName(), p.getValue())).collect(Collectors.toList()); } String contentType = postData.getMimeType(); String postDataText = postData.getText(); @Nullable Long requestBodySize = nullIfNegative(request.getBodySize()); @Nullable String postDataComment = postData.getComment(); return Hars.getRequestPostData(pairs, contentType, postDataText, requestBodySize, postDataComment, exMachinaCharset); } } return null; } }
SstoehrHarBridge implements HarBridge<HarEntry> { @Nullable @Override public ByteSource getRequestPostData(HarEntry entry) throws IOException { HarRequest request = entry.getRequest(); if (request != null) { HarPostData postData = request.getPostData(); if (postData != null) { List<HarPostDataParam> params = postData.getParams(); List<NameValuePair> pairs = null; if (params != null) { pairs = params.stream().map(p -> NameValuePair.of(p.getName(), p.getValue())).collect(Collectors.toList()); } String contentType = postData.getMimeType(); String postDataText = postData.getText(); @Nullable Long requestBodySize = nullIfNegative(request.getBodySize()); @Nullable String postDataComment = postData.getComment(); return Hars.getRequestPostData(pairs, contentType, postDataText, requestBodySize, postDataComment, exMachinaCharset); } } return null; } SstoehrHarBridge();  SstoehrHarBridge(Charset exMachinaCharset); }
SstoehrHarBridge implements HarBridge<HarEntry> { @Nullable @Override public ByteSource getRequestPostData(HarEntry entry) throws IOException { HarRequest request = entry.getRequest(); if (request != null) { HarPostData postData = request.getPostData(); if (postData != null) { List<HarPostDataParam> params = postData.getParams(); List<NameValuePair> pairs = null; if (params != null) { pairs = params.stream().map(p -> NameValuePair.of(p.getName(), p.getValue())).collect(Collectors.toList()); } String contentType = postData.getMimeType(); String postDataText = postData.getText(); @Nullable Long requestBodySize = nullIfNegative(request.getBodySize()); @Nullable String postDataComment = postData.getComment(); return Hars.getRequestPostData(pairs, contentType, postDataText, requestBodySize, postDataComment, exMachinaCharset); } } return null; } SstoehrHarBridge();  SstoehrHarBridge(Charset exMachinaCharset); @Override String getRequestMethod(HarEntry entry); @Override String getRequestUrl(HarEntry entry); @Override Stream<Map.Entry<String, String>> getRequestHeaders(HarEntry entry); @Nullable @Override ByteSource getRequestPostData(HarEntry entry); @Override HarResponseData getResponseData(ParsedRequest request, HarEntry entry, HarResponseEncoding encoding); @Override int getResponseStatus(HarEntry entry); }
SstoehrHarBridge implements HarBridge<HarEntry> { @Nullable @Override public ByteSource getRequestPostData(HarEntry entry) throws IOException { HarRequest request = entry.getRequest(); if (request != null) { HarPostData postData = request.getPostData(); if (postData != null) { List<HarPostDataParam> params = postData.getParams(); List<NameValuePair> pairs = null; if (params != null) { pairs = params.stream().map(p -> NameValuePair.of(p.getName(), p.getValue())).collect(Collectors.toList()); } String contentType = postData.getMimeType(); String postDataText = postData.getText(); @Nullable Long requestBodySize = nullIfNegative(request.getBodySize()); @Nullable String postDataComment = postData.getComment(); return Hars.getRequestPostData(pairs, contentType, postDataText, requestBodySize, postDataComment, exMachinaCharset); } } return null; } SstoehrHarBridge();  SstoehrHarBridge(Charset exMachinaCharset); @Override String getRequestMethod(HarEntry entry); @Override String getRequestUrl(HarEntry entry); @Override Stream<Map.Entry<String, String>> getRequestHeaders(HarEntry entry); @Nullable @Override ByteSource getRequestPostData(HarEntry entry); @Override HarResponseData getResponseData(ParsedRequest request, HarEntry entry, HarResponseEncoding encoding); @Override int getResponseStatus(HarEntry entry); static final Charset DEFAULT_EX_MACHINA_CHARSET; }