本文整理汇总了Java中org.apache.http.NameValuePair类的典型用法代码示例。如果您正苦于以下问题:Java NameValuePair类的具体用法?Java NameValuePair怎么用?Java NameValuePair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NameValuePair类属于org.apache.http包,在下文中一共展示了NameValuePair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cancelOrder
import org.apache.http.NameValuePair; //导入依赖的package包/类
private boolean cancelOrder(BookingInfo bInfo) {
String url = "https://kyfw.12306.cn/otn/queryOrder/cancelNoCompleteMyOrder";
List<NameValuePair> lstParams = new ArrayList<NameValuePair>();
lstParams.add(new BasicNameValuePair("sequence_no", mLstODBInfos.get(0)
.getSequence_no()));
lstParams.add(new BasicNameValuePair("cancel_flag", "cancel_order"));
lstParams.add(new BasicNameValuePair("_json_att", ""));
try {
A6Info a6Json = A6Util
.post(bInfo,
A6Util.makeRefererColl("https://kyfw.12306.cn/otn/queryOrder/initNoComplete"),
url, lstParams);
JSONObject jsonObj = new JSONObject(a6Json.getData());
if (jsonObj.getString("existError").equals("N")) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例2: getRequestParamString
import org.apache.http.NameValuePair; //导入依赖的package包/类
/**
* obtain the get request param
*
* @return the param string
*/
private String getRequestParamString() {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair(SmnConstants.OFFSET, String.valueOf(offset)));
nameValuePairs.add(new BasicNameValuePair(SmnConstants.LIMIT, String.valueOf(limit)));
String param = "";
if (!nameValuePairs.isEmpty()) {
try {
param = EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, Charset.forName("UTF-8")));
} catch (IOException e) {
throw new RuntimeException("get request param error");
}
}
return param;
}
示例3: postForRefreshAndAccessToken
import org.apache.http.NameValuePair; //导入依赖的package包/类
public GoogleIdAndRefreshToken postForRefreshAndAccessToken(String code, String redirectUri) throws IOException
{
HttpPost callbackRequest = new HttpPost(tokenUrl);
List<NameValuePair> parameters = new ArrayList<>();
parameters.addAll(getAuthenticationParameters());
parameters.addAll(Arrays.asList(new BasicNameValuePair("grant_type", "authorization_code"),
new BasicNameValuePair("code", code),
new BasicNameValuePair("redirect_uri", redirectUri)));
callbackRequest.setEntity(new UrlEncodedFormEntity(parameters, StandardCharsets.UTF_8));
try (CloseableHttpResponse callbackResponse = httpClient.execute(callbackRequest)) {
GoogleIdAndRefreshToken googleToken = objectMapper.readValue(IOUtils.toString(callbackResponse.getEntity()
.getContent(),
StandardCharsets.UTF_8),
GoogleIdAndRefreshToken.class);
logger.info("New id token retrieved.");
return googleToken;
}
}
示例4: getPostParameterPairs
import org.apache.http.NameValuePair; //导入依赖的package包/类
@SuppressWarnings("unused")
private static List<NameValuePair> getPostParameterPairs(Map<String, String> postParams) {
List<NameValuePair> result = new ArrayList<NameValuePair>(postParams.size());
for (String key : postParams.keySet()) {
result.add(new BasicNameValuePair(key, postParams.get(key)));
}
return result;
}
示例5: format
import org.apache.http.NameValuePair; //导入依赖的package包/类
/**
* Returns a String that is suitable for use as an <code>application/x-www-form-urlencoded</code>
* list of parameters in an HTTP PUT or HTTP POST.
*
* @param parameters The parameters to include.
* @param encoding The encoding to use.
*/
public static String format (
final List <? extends NameValuePair> parameters,
final String encoding) {
final StringBuilder result = new StringBuilder();
for (final NameValuePair parameter : parameters) {
final String encodedName = encodeFormFields(parameter.getName(), encoding);
final String encodedValue = encodeFormFields(parameter.getValue(), encoding);
if (result.length() > 0) {
result.append(PARAMETER_SEPARATOR);
}
result.append(encodedName);
if (encodedValue != null) {
result.append(NAME_VALUE_SEPARATOR);
result.append(encodedValue);
}
}
return result.toString();
}
示例6: getRequestParamString
import org.apache.http.NameValuePair; //导入依赖的package包/类
/**
* obtain the get request param
*
* @return the param string
*/
private String getRequestParamString() {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
if (!StringUtils.isBlank(protocol)) {
nameValuePairs.add(new BasicNameValuePair(SmnConstants.SMN_PROTOCOL, protocol));
}
if (!StringUtils.isBlank(messageTemplateName)) {
nameValuePairs.add(new BasicNameValuePair(SmnConstants.SMN_MESSAGE_TEMPLATE_NAME, messageTemplateName));
}
nameValuePairs.add(new BasicNameValuePair(SmnConstants.OFFSET, String.valueOf(offset)));
nameValuePairs.add(new BasicNameValuePair(SmnConstants.LIMIT, String.valueOf(limit)));
String param = "";
if (!nameValuePairs.isEmpty()) {
try {
param = EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, Charset.forName("UTF-8")));
} catch (IOException e) {
throw new RuntimeException("get request param error");
}
}
return param;
}
示例7: oauth
import org.apache.http.NameValuePair; //导入依赖的package包/类
/**
* Perform an Oauth2 callback to the Discord servers with the token given by the user's approval
* @param token Token from user
* @param res Passed on response
* @throws ClientProtocolException Error in HTTP protocol
* @throws IOException Encoding exception or error in protocol
* @throws NoAPIKeyException No API keys set
*/
static void oauth(String token, Response res) throws ClientProtocolException, IOException, NoAPIKeyException {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost post = new HttpPost("https://discordapp.com/api/oauth2/token");
List<NameValuePair> nvp = new ArrayList<NameValuePair>();
nvp.add(new BasicNameValuePair("client_id", Bot.getInstance().getApiKeys().get("dashboardid")));
nvp.add(new BasicNameValuePair("client_secret", Bot.getInstance().getApiKeys().get("dashboardsecret")));
nvp.add(new BasicNameValuePair("grant_type", "authorization_code"));
nvp.add(new BasicNameValuePair("code", token));
post.setEntity(new UrlEncodedFormEntity(nvp));
String accessToken;
CloseableHttpResponse response = httpclient.execute(post);
try {
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
JsonObject authJson;
try(BufferedReader buffer = new BufferedReader(new InputStreamReader(entity.getContent()))) {
authJson = Json.parse(buffer.lines().collect(Collectors.joining("\n"))).asObject();
}
accessToken = authJson.getString("access_token", "");
EntityUtils.consume(entity);
getGuilds(res, accessToken);
} finally {
response.close();
}
}
示例8: get
import org.apache.http.NameValuePair; //导入依赖的package包/类
/**
* Make a GET-request to the devRant server.
*
* @param url The url to make the request to.
* @return A {@link JsonObject} containing the response.
*/
JsonObject get(String url, NameValuePair... params) {
StringBuilder finalUrl = new StringBuilder(url).append('?');
List<NameValuePair> paramList = getParameters(params);
// Add all parameters.
try {
for (NameValuePair param : paramList)
finalUrl.append('&').append(param.getName()).append('=').append(URLEncoder.encode(param.getValue(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
// This never happens.
LOGGER.error("Unsupported encoding while trying to encode parameter value.", e);
}
return executeRequest(Request.Get(BASE_URL + finalUrl.toString()));
}
示例9: postLeaveInstance
import org.apache.http.NameValuePair; //导入依赖的package包/类
private void postLeaveInstance() {
AsyncCallbackPair<JSONObject> setInstanceCallback = new AsyncCallbackPair<JSONObject>(){
public void onSuccess(final JSONObject response) {
SetInstance("");
processInstanceLists(response);
FunctionCompleted("LeaveInstance");
}
public void onFailure(final String message) {
WebServiceError("LeaveInstance", message);
}
};
postCommandToGameServer(LEAVE_INSTANCE_COMMAND,
Lists.<NameValuePair>newArrayList(
new BasicNameValuePair(GAME_ID_KEY, GameId()),
new BasicNameValuePair(INSTANCE_ID_KEY, InstanceId()),
new BasicNameValuePair(PLAYER_ID_KEY, UserEmailAddress())),
setInstanceCallback);
}
示例10: post
import org.apache.http.NameValuePair; //导入依赖的package包/类
/**
* httpClient post 获取资源
* @param url
* @param params
* @return
*/
public static String post(String url, Map<String, Object> params) {
log.info(url);
try {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
if (params != null && params.size() > 0) {
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
Set<String> keySet = params.keySet();
for (String key : keySet) {
Object object = params.get(key);
nvps.add(new BasicNameValuePair(key, object==null?null:object.toString()));
}
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
}
CloseableHttpResponse response = httpClient.execute(httpPost);
return EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (Exception e) {
log.error(e);
}
return null;
}
示例11: getParams
import org.apache.http.NameValuePair; //导入依赖的package包/类
public JSONArray getParams(ResourceTimings e) {
JSONArray paramList = new JSONArray();
try {
List<NameValuePair> params = URLEncodedUtils.parse(new URI(e.name), "UTF-8");
for (NameValuePair pair : params) {
JSONObject jsonPair = new JSONObject();
jsonPair.put("name", pair.getName());
jsonPair.put("value", pair.getValue());
paramList.add(jsonPair);
}
} catch (Exception ex) {
return paramList;
}
return paramList;
}
示例12: getAccessTokenByRefreshToken
import org.apache.http.NameValuePair; //导入依赖的package包/类
protected static String getAccessTokenByRefreshToken(Context context, String refreshToken,
long clientId, String clientSecret,
String redirectUri, String tokenType,
String macKey, String macAlgorithm)
throws IOException {
List<NameValuePair> params = new ArrayList();
params.add(new BasicNameValuePair(Constants.PARAM_CLIENT_ID, String.valueOf(clientId)));
params.add(new BasicNameValuePair("grant_type", "refresh_token"));
params.add(new BasicNameValuePair("client_secret", clientSecret));
params.add(new BasicNameValuePair("token_type", SocializeProtocolConstants
.PROTOCOL_KEY_MAC));
params.add(new BasicNameValuePair("redirect_uri", redirectUri));
params.add(new BasicNameValuePair("refresh_token", refreshToken));
params.add(new BasicNameValuePair("token_type", tokenType));
params.add(new BasicNameValuePair("mac_key", macKey));
params.add(new BasicNameValuePair("mac_algorithm", macAlgorithm));
String result = Network.downloadXml(context, new URL(generateUrl(TOKEN_PATH, params)));
if (TextUtils.isEmpty(result)) {
return result;
}
return result.replace(HEADER_FLAG, "");
}
示例13: getRequestParamString
import org.apache.http.NameValuePair; //导入依赖的package包/类
/**
* obtain the get request param
*
* @return the param string
*/
private String getRequestParamString() {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
if (!StringUtils.isBlank(eventType)) {
nameValuePairs.add(new BasicNameValuePair(SmnConstants.EVENT_TYPE, eventType));
}
String param = "";
if (!nameValuePairs.isEmpty()) {
try {
param = EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, Charset.forName("UTF-8")));
} catch (IOException e) {
throw new RuntimeException("get request param error");
}
}
return param;
}
示例14: post
import org.apache.http.NameValuePair; //导入依赖的package包/类
public boolean post(String url, String jsonMessage) throws ClientProtocolException, IOException {
List<NameValuePair> lstParams = new ArrayList<NameValuePair>();
try {
jsonMessage = mEncrypter.encrypt(jsonMessage);
lstParams.add(new BasicNameValuePair("message", jsonMessage));
responseStr = httpHelper.post(null, url, lstParams);
if (responseStr == null || responseStr.equals("")) {
return false;
} else {
responseStr = mEncrypter.decrypt(responseStr);
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例15: setParameter
import org.apache.http.NameValuePair; //导入依赖的package包/类
/**
* Sets parameter of URI query overriding existing value if set. The parameter name and value
* are expected to be unescaped and may contain non ASCII characters.
*/
public URIBuilder setParameter(final String param, final String value) {
if (this.queryParams == null) {
this.queryParams = new ArrayList<NameValuePair>();
}
if (!this.queryParams.isEmpty()) {
for (Iterator<NameValuePair> it = this.queryParams.iterator(); it.hasNext(); ) {
NameValuePair nvp = it.next();
if (nvp.getName().equals(param)) {
it.remove();
}
}
}
this.queryParams.add(new BasicNameValuePair(param, value));
this.encodedQuery = null;
this.encodedSchemeSpecificPart = null;
return this;
}