use of org.apache.http.client.entity.UrlEncodedFormEntity in project OpenRefine by OpenRefine.
the class RefineBroker method getUserId.
// ----------------------------------------------------------------------------------------
@SuppressWarnings("unchecked")
protected String getUserId(HttpServletRequest request) throws Exception {
// This is useful for testing
if (developmentMode) {
return getParameter(request, "uid");
}
String oauth = request.getHeader(DELEGATED_OAUTH_HEADER);
if (oauth == null) {
throw new RuntimeException("The request needs to contain the '" + DELEGATED_OAUTH_HEADER + "' header set to obtain user identity via Freebase.");
}
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
Map<String, String> params = (Map<String, String>) request.getParameterMap();
for (Entry<String, String> e : params.entrySet()) {
formparams.add(new BasicNameValuePair((String) e.getKey(), (String) e.getValue()));
}
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
HttpPost httpRequest = new HttpPost(USER_INFO_URL);
httpRequest.setHeader(OAUTH_HEADER, oauth);
httpRequest.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "OpenRefine Broker");
httpRequest.setEntity(entity);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpRequest, responseHandler);
JSONObject o = new JSONObject(responseBody);
return o.getString("username");
}
use of org.apache.http.client.entity.UrlEncodedFormEntity in project UltimateAndroid by cymcsg.
the class HttpUtils_Deprecated method getResponseStatusCodeFromPostUrl.
/*
* 发送POST请求,通过URL和参数获取服务器反馈应答,通过返回的应答对象 在对数据头进行分析(如获得报文头 报文体等)
*/
public static Map getResponseStatusCodeFromPostUrl(String url, String logininfo, List<NameValuePair> params) throws Exception {
Map rstmap = new HashMap();
if (url.contains("http")) {
} else {
url = "http://t.qingdaonews.com" + url;
}
HttpPost httpRequest = new HttpPost(url);
httpRequest.addHeader("Cookie", logininfo);
if (null != params && params.size() > 0) {
/* 添加请求参数到请求对象 */
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
}
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
StringBuffer sb = new StringBuffer();
String inputLine = "";
rstmap.put("code", httpResponse.getStatusLine().getStatusCode());
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
InputStreamReader is = new InputStreamReader(httpResponse.getEntity().getContent());
BufferedReader in = new BufferedReader(is);
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine);
}
in.close();
rstmap.put("content", sb.toString());
} else {
rstmap.put("content", null);
}
return rstmap;
}
use of org.apache.http.client.entity.UrlEncodedFormEntity in project tdi-studio-se by Talend.
the class RestClient method loginAs.
public void loginAs(String username, String password) {
try {
CookieStore cookieStore = new BasicCookieStore();
httpContext = new BasicHttpContext();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
String loginURL = "/loginservice";
// If you misspell a parameter you will get a HTTP 500 error
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("username", username));
urlParameters.add(new BasicNameValuePair("password", password));
urlParameters.add(new BasicNameValuePair("redirect", "false"));
// UTF-8 is mandatory otherwise you get a NPE
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(urlParameters, "utf-8");
executePostRequest(loginURL, entity);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of org.apache.http.client.entity.UrlEncodedFormEntity in project voltdb by VoltDB.
the class HTTPUtils method callProcOverJSONRaw.
public static String callProcOverJSONRaw(List<NameValuePair> vals, CloseableHttpClient httpclient, HttpPost httppost) throws Exception {
HttpEntity entity = null;
String entityStr = null;
httppost.setEntity(new UrlEncodedFormEntity(vals));
CloseableHttpResponse httpResponse = httpclient.execute(httppost);
BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = reader.readLine()) != null) {
response.append(inputLine);
}
return response.toString();
}
use of org.apache.http.client.entity.UrlEncodedFormEntity in project selenium-tests by Wikia.
the class CommonUtils method sendPost.
public static String sendPost(String apiUrl, String[][] param) {
try {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(apiUrl);
List<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
for (int i = 0; i < param.length; i++) {
paramPairs.add(new BasicNameValuePair(param[i][0], param[i][1]));
}
httpPost.setEntity(new UrlEncodedFormEntity(paramPairs));
HttpResponse response = null;
response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
return EntityUtils.toString(entity);
} catch (UnsupportedEncodingException e) {
PageObjectLogging.log("sendPost", e, false);
return null;
} catch (ClientProtocolException e) {
PageObjectLogging.log("sendPost", e, false);
return null;
} catch (IOException e) {
PageObjectLogging.log("sendPost", e, false);
return null;
}
}
Aggregations