Search in sources :

Example 21 with HttpPost

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);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpGet(org.apache.http.client.methods.HttpGet) HttpRequestWrapper(org.apache.http.client.methods.HttpRequestWrapper) URI(java.net.URI) ProtocolException(org.apache.http.ProtocolException)

Example 22 with HttpPost

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;
    }
}
Also used : SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException)

Example 23 with HttpPost

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"));
}
Also used : HttpRequest(org.apache.http.HttpRequest) HttpPost(org.apache.http.client.methods.HttpPost) Test(org.junit.Test)

Example 24 with HttpPost

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 25 with HttpPost

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HashMap(java.util.HashMap) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) HashMap(java.util.HashMap) Map(java.util.Map) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Aggregations

HttpPost (org.apache.http.client.methods.HttpPost)531 HttpResponse (org.apache.http.HttpResponse)238 StringEntity (org.apache.http.entity.StringEntity)220 Test (org.junit.Test)153 IOException (java.io.IOException)143 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)107 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)99 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)90 ArrayList (java.util.ArrayList)86 NameValuePair (org.apache.http.NameValuePair)84 HttpEntity (org.apache.http.HttpEntity)83 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)68 HttpClient (org.apache.http.client.HttpClient)64 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)63 HttpGet (org.apache.http.client.methods.HttpGet)55 TestHttpClient (io.undertow.testutils.TestHttpClient)54 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)49 ClientProtocolException (org.apache.http.client.ClientProtocolException)49 JsonNode (com.fasterxml.jackson.databind.JsonNode)39 InputStream (java.io.InputStream)29