Java Code Examples for cn.hutool.http.HttpRequest#body()
The following examples show how to use
cn.hutool.http.HttpRequest#body() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommUtils.java From tools-ocr with GNU Lesser General Public License v3.0 | 6 votes |
private static String postMultiData(String url, byte[] data, String boundary, String cookie, String referer) { try { HttpRequest request = HttpUtil.createPost(url).timeout(15000); request.contentType("multipart/form-data; boundary=" + boundary); request.body(data); if (StrUtil.isNotBlank(referer)) { request.header("Referer", referer); } if (StrUtil.isNotBlank(cookie)) { request.cookie(cookie); } HttpResponse response = request.execute(); return WebUtils.getSafeHtml(response); } catch (Exception ex) { StaticLog.error(ex); return null; } }
Example 2
Source File: AbstractOneDriveServiceBase.java From zfile with MIT License | 6 votes |
/** * 根据 RefreshToken 刷新 AccessToken, 返回刷新后的 Token. * * @return 刷新后的 Token */ public OneDriveToken getRefreshToken() { StorageConfig refreshStorageConfig = storageConfigRepository.findByDriveIdAndKey(driveId, StorageConfigConstant.REFRESH_TOKEN_KEY); String param = "client_id=" + getClientId() + "&redirect_uri=" + getRedirectUri() + "&client_secret=" + getClientSecret() + "&refresh_token=" + refreshStorageConfig.getValue() + "&grant_type=refresh_token"; String fullAuthenticateUrl = AUTHENTICATE_URL.replace("{authenticateEndPoint}", getAuthenticateEndPoint()); HttpRequest post = HttpUtil.createPost(fullAuthenticateUrl); post.body(param, "application/x-www-form-urlencoded"); HttpResponse response = post.execute(); return JSONObject.parseObject(response.body(), OneDriveToken.class); }
Example 3
Source File: AbstractOneDriveServiceBase.java From zfile with MIT License | 6 votes |
/** * OAuth2 协议中, 根据 code 换取 access_token 和 refresh_token. * * @param code * 代码 * * @return 获取的 Token 信息. */ public OneDriveToken getToken(String code) { String param = "client_id=" + getClientId() + "&redirect_uri=" + getRedirectUri() + "&client_secret=" + getClientSecret() + "&code=" + code + "&scope=" + getScope() + "&grant_type=authorization_code"; String fullAuthenticateUrl = AUTHENTICATE_URL.replace("{authenticateEndPoint}", getAuthenticateEndPoint()); HttpRequest post = HttpUtil.createPost(fullAuthenticateUrl); post.body(param, "application/x-www-form-urlencoded"); HttpResponse response = post.execute(); return JSONObject.parseObject(response.body(), OneDriveToken.class); }
Example 4
Source File: WebUtils.java From tools-ocr with GNU Lesser General Public License v3.0 | 4 votes |
private static HttpResponse postData(String url, Map<String, Object> data, int contentType, int userAgent, Map<String, String> headers) { try { HttpRequest request = HttpUtil.createPost(url).timeout(10000); if (contentType == 0) { request.contentType("application/x-www-form-urlencoded"); request.form(data); } else if (contentType == 1) { request.body(data.values().iterator().next().toString(), "application/json;charset=UTF-8"); } else { request.contentType("application/x-www-form-urlencoded"); request.body(data.values().iterator().next().toString()); } if (headers == null) { headers = new Hashtable<>(); } switch (userAgent) { case 1: headers.put("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"); break; case 2: headers.put("User-Agent", "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19"); break; case 3: headers.put("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)"); break; case 4: headers.put("User-Agent", "NativeHost"); break; case 5: headers.put("User-Agent", "Apache-HttpClient/UNAVAILABLE (java 1.4)"); break; case 6: headers.put("User-Agent", "Mozilla/5.0 (iPad; CPU OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B466 Safari/600.1.4"); break; case 7: headers.put("User-Agent", "okhttp/2.7.5"); break; case 10: headers.put("User-Agent", "Mozilla/5.0 (Linux; Android 5.1.1; oppo r11 plus Build/LMY48Z) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 SogouSearch Android1.0 version3.0"); break; default: headers.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"); break; } request.addHeaders(headers); return request.execute(); } catch (Exception ex) { StaticLog.error(ex); return null; } }