public int get(String url) throws HttpException, IOException { final GetMethod get = new GetMethod(url); get.getParams().setContentCharset("UTF-8"); return httpClient.executeMethod(get); }
private void connect() throws IOException { Preconditions.checkArgument(httpGetMethod==null, "Http resource must be release before re-connecting"); httpGetMethod = new GetMethod(url); httpGetMethod.getParams().setContentCharset(defaultCharset); httpClient.executeMethod(httpGetMethod); }
public int post(String url, Map<String,String> properties) throws HttpException, IOException { final PostMethod post = new PostMethod(url); post.getParams().setContentCharset("UTF-8"); for(Entry<String, String> e : properties.entrySet()) { post.addParameter(e.getKey(), e.getValue()); } return httpClient.executeMethod(post); }
param.setContentCharset("UTF-8");
protected String post(String path, NameValuePair[] data) { PostMethod req = new PostMethod(path); req.setRequestBody(data); req.getParams().setContentCharset("utf-8"); return send(req); }
PostMethod post = new PostMethod(slackUrl); post.addParameter("payload", payload); post.getParams().setContentCharset("UTF-8"); Integer responseCode=null; try {
private static String test(String text){ HttpClient client = new HttpClient(); JSONObject json = new JSONObject(); json.put("text", text); NameValuePair[] nameValuePairs = new NameValuePair[1]; nameValuePairs[0] = new NameValuePair("payload", json.toString()); PostMethod method = new PostMethod("http://jira.9tong.com/rest/webhooks/1.0/webhook/2?os_authType=basic&os_username=yidejun&os_password=jt123456"); method.setRequestBody(nameValuePairs); HttpMethodParams param = method.getParams(); param.setContentCharset("UTF-8"); try { client.executeMethod(method); return method.getResponseBodyAsString(); } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } }
param.setContentCharset("UTF-8");
getMethod.getParams().setContentCharset(null); // to avoid wrong Charsets! getMethod.setQueryString("SERVICE=" + service + "&REQUEST=GetCapabilities");
public void publish(String message, String color) { for (String roomId : roomIds) { logger.info("Posting: " + from + " to " + roomId + ": " + message + " " + color); HttpClient client = getHttpClient(); String url = "https://" + host + "/v1/rooms/message?auth_token=" + token; PostMethod post = new PostMethod(url); try { post.addParameter("from", from); post.addParameter("room_id", roomId); post.addParameter("message", message); post.addParameter("color", color); post.addParameter("notify", shouldNotify(color)); post.getParams().setContentCharset("UTF-8"); int responseCode = client.executeMethod(post); String response = post.getResponseBodyAsString(); if(responseCode != HttpStatus.SC_OK || ! response.contains("\"sent\"")) { logger.log(Level.WARNING, "HipChat post may have failed. Response: " + response); } } catch (Exception e) { logger.log(Level.WARNING, "Error posting to HipChat", e); } finally { post.releaseConnection(); } } }
protected void put(String path, NameValuePair[] data) { PutMethod req = new PutMethod(path); req.setRequestBody(EncodingUtil.formUrlEncode(data, "utf-8")); req.getParams().setContentCharset("utf-8"); send(req); }
public Response post(String url, PostParameter[] params, Boolean WithTokenHeader) throws WeiboException { log("Request:"); log("POST" + url); PostMethod postMethod = new PostMethod(url); for (int i = 0; i < params.length; i++) { postMethod.addParameter(params[i].getName(), params[i].getValue()); } HttpMethodParams param = postMethod.getParams(); param.setContentCharset("UTF-8"); if (WithTokenHeader) { return httpRequest(postMethod); } else { return httpRequest(postMethod, WithTokenHeader); } }
param.setContentCharset("UTF-8");
public Response post(String url, PostParameter[] params, Boolean WithTokenHeader) throws WeiboException { log("Request:"); log("POST" + url); PostMethod postMethod = new PostMethod(url); for (int i = 0; i < params.length; i++) { postMethod.addParameter(params[i].getName(), params[i].getValue()); } HttpMethodParams param = postMethod.getParams(); param.setContentCharset("UTF-8"); if (WithTokenHeader) { return httpRequest(postMethod); } else { return httpRequest(postMethod, WithTokenHeader); } }
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); } else { post.getParams().setContentCharset("UTF-8"); for(NameValuePair e : nodeProperties) { post.addParameter(e.getName(),e.getValue());
client = new org.apache.commons.httpclient.HttpClient(new HttpClientParams(), connectionManager); method.getParams().setContentCharset( "UTF-8");
post.getParams().setContentCharset(StandardCharsets.ISO_8859_1.name()); if (request.getByteData() != null) { post.setRequestEntity(new ByteArrayRequestEntity(request.getByteData()));
method.getParams().setContentCharset(webRequestSettings.getCharset());
method.getParams().setContentCharset(webRequestSettings.getCharset());
method.getParams().setContentCharset(webRequestSettings.getCharset());