当前位置: 首页>>代码示例>>Java>>正文


Java UrlEncodedFormEntity.setContentType方法代码示例

本文整理汇总了Java中org.apache.http.client.entity.UrlEncodedFormEntity.setContentType方法的典型用法代码示例。如果您正苦于以下问题:Java UrlEncodedFormEntity.setContentType方法的具体用法?Java UrlEncodedFormEntity.setContentType怎么用?Java UrlEncodedFormEntity.setContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.entity.UrlEncodedFormEntity的用法示例。


在下文中一共展示了UrlEncodedFormEntity.setContentType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doPost

import org.apache.http.client.entity.UrlEncodedFormEntity; //导入方法依赖的package包/类
/**
 * post form
 *
 * @param host
 * @param path
 * @param method
 * @param headers
 * @param querys
 * @param bodys
 * @return
 * @throws Exception
 */
public static HttpResponse doPost(String host, String path, String method,
                                  Map<String, String> headers,
                                  Map<String, String> querys,
                                  Map<String, String> bodys)
        throws Exception {
    HttpClient httpClient = wrapClient(host);

    HttpPost request = new HttpPost(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
        request.addHeader(e.getKey(), e.getValue());
    }

    if (bodys != null) {
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();

        for (String key : bodys.keySet()) {
            nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
        }
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
        formEntity.setContentType("application/x-www-form-urlencoded");

        request.setEntity(formEntity);
    }

    return httpClient.execute(request);
}
 
开发者ID:JiaXiaohei,项目名称:elasticjob-stock-push,代码行数:39,代码来源:HttpUtils.java

示例2: doPost

import org.apache.http.client.entity.UrlEncodedFormEntity; //导入方法依赖的package包/类
/**
 * post form
 *
 * @param host
 * @param path
 * @param method
 * @param headers
 * @param querys
 * @param bodys
 * @return
 * @throws Exception
 */
public static HttpResponse doPost(String host, String path, String method,
                                  Map<String, String> headers,
                                  Map<String, String> querys,
                                  Map<String, String> bodys)
        throws Exception {
    HttpClient httpClient = wrapClient(host);

    HttpPost request = new HttpPost(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
        request.addHeader(e.getKey(), e.getValue());
    }

    if (bodys != null) {
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();

        for (String key : bodys.keySet()) {
            nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
        }
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
        formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
        request.setEntity(formEntity);
    }

    return httpClient.execute(request);
}
 
开发者ID:JiaXiaohei,项目名称:elasticjob-oray-client,代码行数:38,代码来源:HttpUtils.java

示例3: doPost

import org.apache.http.client.entity.UrlEncodedFormEntity; //导入方法依赖的package包/类
/**
 * post form
 * 
 * @param host
 * @param path
 * @param method
 * @param headers
 * @param querys
 * @param bodys
 * @return
 * @throws Exception
 */
public static HttpResponse doPost(String host, String path, String method, 
		Map<String, String> headers, 
		Map<String, String> querys, 
		Map<String, String> bodys)
           throws Exception {    	
   	HttpClient httpClient = wrapClient(host);

   	HttpPost request = new HttpPost(buildUrl(host, path, querys));
       for (Map.Entry<String, String> e : headers.entrySet()) {
       	request.addHeader(e.getKey(), e.getValue());
       }

       if (bodys != null) {
           List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();

           for (String key : bodys.keySet()) {
               nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
           }
           UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
           formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
           request.setEntity(formEntity);
       }

       return httpClient.execute(request);
   }
 
开发者ID:linkingli,项目名称:FaceDistinguish,代码行数:38,代码来源:HttpUtils.java

示例4: buildFormEntity

import org.apache.http.client.entity.UrlEncodedFormEntity; //导入方法依赖的package包/类
/**
 * 构建FormEntity
 * 
 * @param formParam
 * @return
 * @throws UnsupportedEncodingException
 */
private static UrlEncodedFormEntity buildFormEntity(Map<String, String> formParam)
        throws UnsupportedEncodingException {
    if (formParam != null) {
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();

        for (String key : formParam.keySet()) {
            nameValuePairList.add(new BasicNameValuePair(key, formParam.get(key)));
        }
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Constants.ENCODING);
        formEntity.setContentType(ContentType.CONTENT_TYPE_FORM);
        return formEntity;
    }

    return null;
}
 
开发者ID:linkingli,项目名称:FaceDistinguish,代码行数:23,代码来源:HttpUtil.java

示例5: getEntity

import org.apache.http.client.entity.UrlEncodedFormEntity; //导入方法依赖的package包/类
public static HttpEntity getEntity(MultiValuedMap fields, String mediaType) {
    List<NameValuePair> list = new ArrayList<>(fields.size());
    for (Map.Entry<String, List> entry : fields.entrySet()) {
        String stringValue;
        List values = entry.getValue();
        if (values == null) {
            stringValue = null;
        } else if (values.size() == 1) {
            Object value = values.get(0);
            if (value == null) {
                stringValue = null;
            } else if (value instanceof String) {
                stringValue = (String) value;
            } else {
                stringValue = value.toString();
            }
        } else {
            stringValue = StringUtils.join(values, ',');
        }
        list.add(new BasicNameValuePair(entry.getKey(), stringValue));
    }
    try {
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list);
        entity.setContentType(mediaType);
        return entity;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:intuit,项目名称:karate,代码行数:30,代码来源:ApacheHttpUtils.java

示例6: genFusiontablesQuery

import org.apache.http.client.entity.UrlEncodedFormEntity; //导入方法依赖的package包/类
/**
 * Generate a FusionTables POST request
 */
// To be deprecated, based on the old API
private HttpUriRequest genFusiontablesQuery(String query) throws IOException {
  HttpPost request = new HttpPost(FUSION_QUERY_URL);
  ArrayList<BasicNameValuePair> pair = new ArrayList<BasicNameValuePair>(1);
  pair.add(new BasicNameValuePair("sql", query));
  UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pair, "UTF-8");
  entity.setContentType("application/x-www-form-urlencoded");
  request.setEntity(entity);
  return request;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:14,代码来源:FusiontablesControl.java


注:本文中的org.apache.http.client.entity.UrlEncodedFormEntity.setContentType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。