本文整理匯總了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;
}