use of org.apache.http.client.methods.HttpPost in project webmagic by code4craft.
the class CustomRedirectStrategy method getRedirect.
@Override
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
URI uri = getLocationURI(request, response, context);
String method = request.getRequestLine().getMethod();
if ("post".equalsIgnoreCase(method)) {
try {
HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper) request;
httpRequestWrapper.setURI(uri);
httpRequestWrapper.removeHeaders("Content-Length");
return httpRequestWrapper;
} catch (Exception e) {
logger.error("强转为HttpRequestWrapper出错");
}
return new HttpPost(uri);
} else {
return new HttpGet(uri);
}
}
use of org.apache.http.client.methods.HttpPost in project aws-iam-ldap-bridge by denismo.
the class IAMAccountPasswordValidator method verifyIAMPassword.
@Override
public boolean verifyIAMPassword(Entry user, String pw) throws LdapInvalidAttributeValueException, LdapAuthenticationException {
try {
LOG.debug("Verifying {} {} with accessKey <hidden> and secretKey <hidden>", "user", user.get("uid").getString());
HttpClient client = new SystemDefaultHttpClient();
HttpPost post = new HttpPost("https://signin.aws.amazon.com/oauth");
post.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36");
post.setHeader("Referer", "https://signin.aws.amazon.com/oauth");
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("client_id", "arn:aws:iam::015428540659:user/homepage"));
urlParameters.add(new BasicNameValuePair("isIAMUser", "1"));
urlParameters.add(new BasicNameValuePair("account", user.get("accountNumber").getString()));
urlParameters.add(new BasicNameValuePair("username", user.get("uid").getString()));
urlParameters.add(new BasicNameValuePair("password", pw));
urlParameters.add(new BasicNameValuePair("Action", "login"));
urlParameters.add(new BasicNameValuePair("redirect_uri", "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true"));
urlParameters.add(new BasicNameValuePair("forceMobileApp", ""));
urlParameters.add(new BasicNameValuePair("forceMobileLayout", ""));
urlParameters.add(new BasicNameValuePair("mfaLoginFailure", ""));
urlParameters.add(new BasicNameValuePair("RemainingExpiryPeriod", ""));
urlParameters.add(new BasicNameValuePair("mfacode", ""));
urlParameters.add(new BasicNameValuePair("next_mfacode", ""));
post.setEntity(new UrlEncodedFormEntity(urlParameters, Charset.forName("UTF-8")));
HttpResponse response = client.execute(post);
return containsHeaders(response, "aws-account-alias", "aws-creds");
} catch (IOException e) {
LOG.error("Exception validating password for " + user.get("uid").getString(), e);
return false;
} catch (RuntimeException t) {
LOG.error("Exception validating password for " + user.get("uid").getString(), t);
throw t;
}
}
use of org.apache.http.client.methods.HttpPost in project metrics by dropwizard.
the class HttpClientMetricNameStrategiesTest method hostAndMethodWithNameInWrappedRequest.
@Test
public void hostAndMethodWithNameInWrappedRequest() throws URISyntaxException {
HttpRequest request = rewriteRequestURI(new HttpPost("http://my.host.com/whatever"));
assertThat(HOST_AND_METHOD.getNameFor("some-service", request), is("org.apache.http.client.HttpClient.some-service.my.host.com.post-requests"));
}
use of org.apache.http.client.methods.HttpPost in project Trello-Android by chrisHoekstra.
the class TrelloService method addCard.
public Boolean addCard(String boardListId, String name) {
Boolean result = false;
ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("key", PUBLIC_KEY));
params.add(new BasicNameValuePair("token", mToken));
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("idList", boardListId));
HttpPost httpPost = new HttpPost(TRELLO_API_URL + "cards?" + URLEncodedUtils.format(params, "UTF-8"));
HttpClient httpClient = getHttpClient();
try {
httpPost.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
HttpResponse response = httpClient.execute(httpPost, mContext);
if (response != null) {
result = true;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
use of org.apache.http.client.methods.HttpPost 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;
}
Aggregations