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