當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。