Example usage for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity

List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity

Introduction

In this page you can find the example usage for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity.

Prototype

public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters, final Charset charset) 

Source Link

Document

Constructs a new UrlEncodedFormEntity with the list of parameters in the specified encoding.

Usage

From source file:org.fcrepo.integration.webhooks.FedoraWebhooksIT.java

public void deleteWebhookTest() throws Exception {
    final HttpPost method = new HttpPost(serverAddress + "/fcr:webhooks/callback_id");

    final List<NameValuePair> formparams = new ArrayList<NameValuePair>();

    formparams.add(new BasicNameValuePair("callbackUrl", RESTAPI_NAMESPACE + "/fake:url"));
    final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
    method.setEntity(entity);/*from ww w.  j a va2  s.c o m*/

    assertEquals(201, getStatus(method));

    final HttpDelete delete_method = new HttpDelete(serverAddress + "/fcr:webhooks/callback_id");

    assertEquals(204, getStatus(delete_method));
}

From source file:rs.htec.rest.entities.services.FileUpload.java

@POST
@Path("/upload-on-server")
@Consumes("multipart/form-data")
public Response uploadFileOnServer(MultipartFormDataInput slika) throws IOException { // @MultipartForm FileUploadForm form2

    HttpClient client = new DefaultHttpClient();

    try {/*from   www  . j  a  v a  2s. co  m*/
        HttpPost post = new HttpPost(KeycloakUriBuilder.fromUri("http://10.10.0.40:8080/auth")
                .path(ServiceUrlConstants.TOKEN_PATH).build("demo"));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("username", "marko@htec.rs"));
        formparams.add(new BasicNameValuePair("password", "mikimaus8"));
        formparams.add(new BasicNameValuePair(OAuth2Constants.GRANT_TYPE, "password"));
        formparams.add(new BasicNameValuePair(OAuth2Constants.CLIENT_ID, "RESTEasyTestPublic"));
        UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(form);

        HttpResponse response = client.execute(post);
        int status = response.getStatusLine().getStatusCode();
        HttpEntity entity = response.getEntity();
        if (status != 200) {
            String json = getContent(entity);
            throw new IOException("Bad status: " + status + " response: " + json);
        }
        if (entity == null) {
            throw new IOException("No Entity");
        }
        String json = getContent(entity);
        JSONParser parser = new JSONParser();
        JSONObject job = (JSONObject) parser.parse(json);

        System.out.println("JSON *************** " + json);

        //            HttpPost post2 = new HttpPost("http://10.10.0.40:8080/RESTEasyTest/rest/multipart/upload");
        //            saljiSliku.setHeader("Authorization", "bearer " + (String) job.get("access_token"));
        return Response.ok().entity("").build();
    } catch (ParseException ex) {
        Logger.getLogger(FileUpload.class.getName()).log(Level.SEVERE, null, ex);
        return Response.ok().entity(ex.getMessage()).build();
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:costumetrade.common.wenqian.util.WQSignUtils.java

/**
 * ?//from   w ww .  j a va  2  s.  com
 * 
 * @param token
 *            ??
 * @param entName
 *            ??????
 * @param adminUser
 *            ??
 * @param adminPhone
 *            ?
 * @param certType
 *            
 * @param licenseCode
 *            ??
 * @param adminIdenCode
 *            ??
 * @return ???(true:? false:)
 */
public static boolean syncUsertowq(String token, String entName, String adminUser, String adminPhone,
        Integer certType, String licenseCode, String adminIdenCode) {
    boolean bool = false;
    try {
        if (StringUtils.isNotEmpty(token)) {
            List<BasicNameValuePair> nvps = new ArrayList<>();
            nvps.add(new BasicNameValuePair("client_id", WQAPIConstants.CLIENT_ID));
            nvps.add(new BasicNameValuePair("access_token", token));
            nvps.add(new BasicNameValuePair("ent_name", entName));// ???
            nvps.add(new BasicNameValuePair("admin_user", adminUser));// ??
            nvps.add(new BasicNameValuePair("admin_phone", adminPhone));// ?
            nvps.add(new BasicNameValuePair("share_id", adminPhone));// 
            nvps.add(new BasicNameValuePair("admin_user", adminUser));
            nvps.add(new BasicNameValuePair("admin_user", adminUser));

            if (certType != null) {
                nvps.add(new BasicNameValuePair("cert_type", String.valueOf(certType)));
            }
            if (StringUtils.isNotEmpty(licenseCode)) {
                nvps.add(new BasicNameValuePair("license_code", licenseCode));
            }
            if (StringUtils.isNotEmpty(adminIdenCode)) {
                nvps.add(new BasicNameValuePair("admin_iden_code", adminIdenCode));
            }

            String response = HttpClientUtils.doPost(WQAPIConstants.sync_user_api,
                    new UrlEncodedFormEntity(nvps, StandardCharsets.UTF_8));
            System.err.println(response);
            JSONObject responseJSON = JSONObject.parseObject(response);
            if (responseJSON.containsKey("error_code")) {
                int errorcode = responseJSON.getIntValue("error_code");
                if (errorcode == WQAPIConstants.success) {
                    bool = true;
                } else {
                    if (errorcode == WQAPIConstants.phone_exist_error
                            || errorcode == WQAPIConstants.company_exist_error
                            || errorcode == WQAPIConstants.user_exist_error) {
                        // ??
                        bool = true;
                    }
                }
            }
        }
    } catch (Exception e) {
        bool = false;
        e.printStackTrace();
    }
    return bool;
}

From source file:com.wms.ezyoukuuploader.sdk.task.FetchYoukuAccessTokenTask.java

@SuppressWarnings("deprecation")
@Override//from  w  w  w. ja v a2 s.  co m
protected String doInBackground(String... params) {
    // params[0] is refresh token
    String refreshToken = params[0];

    String accessToken = null;

    HttpPost httpPost = new HttpPost(YoukuConstants.YOUKU_OAUTH2_URL);
    List<NameValuePair> parameters = new ArrayList<NameValuePair>();
    parameters.add(new BasicNameValuePair(YoukuConstants.PARAM_CLIENT_ID,
            context.getString(R.string.YOUKU_APP_CLIENT_ID)));
    parameters.add(new BasicNameValuePair(YoukuConstants.PARAM_CLIENT_SECRET,
            context.getString(R.string.YOUKU_APP_CLIENT_SECRET)));
    parameters.add(
            new BasicNameValuePair(YoukuConstants.PARAM_GRANT_TYPE, YoukuConstants.GRANT_TYPE_REFRESH_TOKEN));
    parameters.add(new BasicNameValuePair(YoukuConstants.PARAM_REFRESH_TOKEN, refreshToken));
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(parameters, HTTP.UTF_8));
        HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost);
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            String result = EntityUtils.toString(httpResponse.getEntity());
            JSONObject object = new JSONObject(result);
            accessToken = object.getString(YoukuConstants.PARAM_ACCESS_TOKEN);
            String newRefreshToken = object.getString(YoukuConstants.PARAM_REFRESH_TOKEN);
            SharedPreferenceUtil.savePreferenceItemByName(context, SharedPreferenceUtil.YoukuRefreshToken,
                    newRefreshToken);
            SharedPreferenceUtil.savePreferenceItemByName(context, SharedPreferenceUtil.YoukuAccessToken,
                    accessToken);
        }
    } catch (Exception e) {
        // accessToken will remain null
    }
    ;
    return accessToken;
}