本文整理汇总了Java中org.apache.commons.httpclient.NameValuePair.setName方法的典型用法代码示例。如果您正苦于以下问题:Java NameValuePair.setName方法的具体用法?Java NameValuePair.setName怎么用?Java NameValuePair.setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.NameValuePair
的用法示例。
在下文中一共展示了NameValuePair.setName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSinaTokenAndUid
import org.apache.commons.httpclient.NameValuePair; //导入方法依赖的package包/类
/**
* 获取新浪登录认证token和用户id
*
* @param code
* @param host
* @return
*/
public static final JSONObject getSinaTokenAndUid(String code, String host) {
JSONObject json = null;
try {
// 获取令牌
String tokenUrl = Resources.THIRDPARTY.getString("accessTokenURL_sina");
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>();
NameValuePair params1 = new NameValuePair();
params1.setName("client_id");
params1.setValue(Resources.THIRDPARTY.getString("app_id_sina"));
list.add(params1);
NameValuePair params2 = new NameValuePair();
params2.setName("client_secret");
params2.setValue(Resources.THIRDPARTY.getString("app_key_sina"));
list.add(params2);
NameValuePair params3 = new NameValuePair();
params3.setName("grant_type");
params3.setValue("authorization_code");
list.add(params3);
NameValuePair params4 = new NameValuePair();
params4.setName("redirect_uri");
params4.setValue("http://" + host + Resources.THIRDPARTY.getString("redirect_url_sina"));
list.add(params4);
NameValuePair params5 = new NameValuePair();
params5.setName("code");
params5.setValue(code);
list.add(params5);
String tokenRes = HttpUtil.httpClientPost(tokenUrl, list);
// String tokenRes = httpClient(tokenUrl);
// {"access_token":"2.00AvYzKGWraycB344b3eb242NUbiQB","remind_in":"157679999","expires_in":157679999,"uid":"5659232590"}
if (tokenRes != null && tokenRes.indexOf("access_token") > -1) {
json = JSONObject.parseObject(tokenRes);
} else {
throw new IllegalArgumentException(Resources.getMessage("THIRDPARTY.LOGIN.NOTOKEN", "sina"));
}
} catch (Exception e) {
logger.error("", e);
}
return json;
}
示例2: getSinaTokenAndUid
import org.apache.commons.httpclient.NameValuePair; //导入方法依赖的package包/类
/**
* 获取新浪登录认证token和用户id
*
* @param code
* @param type
* @return
*/
public static final JSONObject getSinaTokenAndUid(String code, String host) {
JSONObject json = null;
try {
// 获取令牌
String tokenUrl = Resources.THIRDPARTY.getString("accessTokenURL_sina");
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>();
NameValuePair params1 = new NameValuePair();
params1.setName("client_id");
params1.setValue(Resources.THIRDPARTY.getString("app_id_sina"));
list.add(params1);
NameValuePair params2 = new NameValuePair();
params2.setName("client_secret");
params2.setValue(Resources.THIRDPARTY.getString("app_key_sina"));
list.add(params2);
NameValuePair params3 = new NameValuePair();
params3.setName("grant_type");
params3.setValue("authorization_code");
list.add(params3);
NameValuePair params4 = new NameValuePair();
params4.setName("redirect_uri");
params4.setValue("http://" + host + Resources.THIRDPARTY.getString("redirect_url_sina"));
list.add(params4);
NameValuePair params5 = new NameValuePair();
params5.setName("code");
params5.setValue(code);
list.add(params5);
String tokenRes = HttpUtil.httpClientPost(tokenUrl, list);
// String tokenRes = httpClient(tokenUrl);
// {"access_token":"2.00AvYzKGWraycB344b3eb242NUbiQB","remind_in":"157679999","expires_in":157679999,"uid":"5659232590"}
if (tokenRes != null && tokenRes.indexOf("access_token") > -1) {
json = JSONObject.parseObject(tokenRes);
} else {
throw new IllegalArgumentException(Resources.getMessage("THIRDPARTY.LOGIN.NOTOKEN", "sina"));
}
} catch (Exception e) {
logger.error(e);
}
return json;
}