本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}