本文整理汇总了Java中org.apache.commons.httpclient.params.HttpMethodParams.setContentCharset方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethodParams.setContentCharset方法的具体用法?Java HttpMethodParams.setContentCharset怎么用?Java HttpMethodParams.setContentCharset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.params.HttpMethodParams
的用法示例。
在下文中一共展示了HttpMethodParams.setContentCharset方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendSms
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
/**
* 发短信
*
* @param apikey apikey
* @param text 短信内容
* @param mobile 接受的手机号
* @return json格式字符串
* @throws IOException
*/
public static String sendSms(String apikey, String text, String mobile){
HttpClient client = new HttpClient();
NameValuePair[] nameValuePairs = new NameValuePair[3];
nameValuePairs[0] = new NameValuePair("apikey", apikey);
nameValuePairs[1] = new NameValuePair("text", text);
nameValuePairs[2] = new NameValuePair("mobile", mobile);
PostMethod method = new PostMethod(URI_SEND_SMS);
method.setRequestBody(nameValuePairs);
HttpMethodParams param = method.getParams();
param.setContentCharset(ENCODING);
try {
client.executeMethod(method);
return method.getResponseBodyAsString();
} catch (IOException ex) {
throw new RuntimeException("sendSms error", ex);
} finally {
method.releaseConnection();
HttpConnectionManager connectionManager = client.getHttpConnectionManager();
((SimpleHttpConnectionManager)connectionManager).shutdown();
}
}
示例2: post
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
public Response post(String url, PostParameter[] params,
Boolean WithTokenHeader, PostParameter[] headers)
throws MxException {
PostMethod postMethod = new PostMethod(url);
for (int i = 0; i < params.length; i++) {
String pValue = params[i].getValue();
if (pValue != null) {
postMethod.addParameter(params[i].getName(),
params[i].getValue());
}
}
HttpMethodParams param = postMethod.getParams();
param.setContentCharset("UTF-8");
if (WithTokenHeader) {
return httpRequest(postMethod, headers);
} else {
return httpRequest(postMethod, WithTokenHeader, headers, null);
}
}
示例3: post
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
public Response post(String url, PostParameter[] params,
Boolean WithTokenHeader) throws WeiboException {
log("Request:");
log("POST" + url);
PostMethod postMethod = new PostMethod(url);
for (int i = 0; i < params.length; i++) {
postMethod.addParameter(params[i].getName(), params[i].getValue());
}
HttpMethodParams param = postMethod.getParams();
param.setContentCharset("UTF-8");
if (WithTokenHeader) {
return httpRequest(postMethod);
} else {
return httpRequest(postMethod, WithTokenHeader);
}
}
示例4: getUserInfo
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
/**
* 取账户信息
*
* @return json格式字符串
* @throws IOException
*/
public static String getUserInfo(String apikey) throws IOException {
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(URI_GET_USER_INFO + "?apikey=" + apikey);
HttpMethodParams param = method.getParams();
param.setContentCharset(ENCODING);
client.executeMethod(method);
return method.getResponseBodyAsString();
}
示例5: tplSendSms
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
/**
* 通过模板发送短信
*
* @param apikey apikey
* @param tpl_id 模板id
* @param tpl_value 模板变量值
* @param mobile 接受的手机号
* @return json格式字符串
* @throws IOException
*/
public static String tplSendSms(String apikey, long tpl_id, String tpl_value, String mobile) throws IOException {
HttpClient client = new HttpClient();
NameValuePair[] nameValuePairs = new NameValuePair[4];
nameValuePairs[0] = new NameValuePair("apikey", apikey);
nameValuePairs[1] = new NameValuePair("tpl_id", String.valueOf(tpl_id));
nameValuePairs[2] = new NameValuePair("tpl_value", tpl_value);
nameValuePairs[3] = new NameValuePair("mobile", mobile);
PostMethod method = new PostMethod(URI_TPL_SEND_SMS);
method.setRequestBody(nameValuePairs);
HttpMethodParams param = method.getParams();
param.setContentCharset(ENCODING);
client.executeMethod(method);
return method.getResponseBodyAsString();
}
示例6: post
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
public Response post(String url, PostParameter[] params,
Boolean WithTokenHeader, String token) throws WeiboException {
log("Request:");
log("POST" + url);
PostMethod postMethod = new PostMethod(url);
for (int i = 0; i < params.length; i++) {
postMethod.addParameter(params[i].getName(), params[i].getValue());
}
HttpMethodParams param = postMethod.getParams();
param.setContentCharset("UTF-8");
return httpRequest(postMethod, WithTokenHeader, token);
}
示例7: post
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
public Response post(String url, PostParameter[] params, Boolean WithTokenHeader, String token)
throws WeiboException {
log("Request:");
log("POST" + url);
PostMethod postMethod = new PostMethod(url);
for (int i = 0; i < params.length; i++) {
postMethod.addParameter(params[i].getName(), params[i].getValue());
}
HttpMethodParams param = postMethod.getParams();
param.setContentCharset("UTF-8");
return httpRequest(postMethod, WithTokenHeader, token);
}
示例8: checkAmount
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
/**
* 查询余额
*
* @return
*/
@Override
public String checkAmount() throws IOException {
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(URI_GET_USER_INFO + "?apikey=" + apikey);
HttpMethodParams param = method.getParams();
param.setContentCharset(ENCODING);
client.executeMethod(method);
String jsonBody = method.getResponseBodyAsString();
return jsonBody;
}
示例9: post
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
public Response post(String url, PostParameter[] params, Boolean WithTokenHeader, PostParameter[] headers) throws MxException {
log("Request:");
log("POST:" + url);
PostMethod postMethod = new PostMethod(url);
for (int i = 0; i < params.length; i++) {
postMethod.addParameter(params[i].getName(), params[i].getValue());
}
HttpMethodParams param = postMethod.getParams();
param.setContentCharset("UTF-8");
if (WithTokenHeader) {
return httpRequest(postMethod, headers);
} else {
return httpRequest(postMethod, WithTokenHeader, headers);
}
}
示例10: getStandardizedPlaceNames
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
public Map<String,String> getStandardizedPlaceNames(Set<String> names, PrintWriter err) throws IOException, SAXException, XPathExpressionException
{
Map<String,String> result = new HashMap<String,String>();
String query = Util.join("|", names);
String url = "http://"+placeServer+"/placestandardize";
PostMethod m = new PostMethod(url);
NameValuePair[] nvp = new NameValuePair[2];
nvp[0] = new NameValuePair("q", query);
nvp[1] = new NameValuePair("wt", "xml");
m.setRequestBody(nvp);
HttpMethodParams params = new HttpMethodParams();
params.setContentCharset("UTF-8");
params.setHttpElementCharset("UTF-8");
params.setParameter("http.protocol.content-charset", "UTF-8");
m.setParams(params);
m.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
int numTries = 0;
while (numTries++ < 3) {
try {
client.executeMethod(m);
break;
}
catch (IOException e) {
resetClient();
}
}
String response = m.getResponseBodyAsString();
Document doc = db.parse(new InputSource(new StringReader(response)));
NodeList lstNodes = (NodeList) lstExpression.evaluate(doc, XPathConstants.NODESET);
for (int i=0; i < lstNodes.getLength(); i++)
{
Node node = lstNodes.item(i);
String q = (String) queryExpression.evaluate(node, XPathConstants.STRING);
String placeTitle = (String)placeTitleExpression.evaluate(node, XPathConstants.STRING);
String error = (String) errorExpression.evaluate(node, XPathConstants.STRING);
if (err != null && !Util.isEmpty(error)) {
err.println(q);
}
placeTitle = getRedirTarget(placeTitle);
result.put(q,placeTitle);
}
return result;
}