當前位置: 首頁>>代碼示例>>Java>>正文


Java NameValuePair類代碼示例

本文整理匯總了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;
}
 
開發者ID:SShineTeam,項目名稱:Huochexing12306,代碼行數:22,代碼來源:A6OrderAty.java

示例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;
}
 
開發者ID:SimpleMessageNotification,項目名稱:smn-sdk-java,代碼行數:22,代碼來源:ListTopicsRequest.java

示例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;
    }
}
 
開發者ID:coveo,項目名稱:k8s-proxy,代碼行數:21,代碼來源:GoogleTokenRetriever.java

示例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;
}
 
開發者ID:wangzhaosheng,項目名稱:publicProject,代碼行數:9,代碼來源:HttpClientStack.java

示例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();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:URLEncodedUtils.java

示例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;
}
 
開發者ID:SimpleMessageNotification,項目名稱:smn-sdk-java,代碼行數:29,代碼來源:ListMessageTemplatesRequest.java

示例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();
	}
}
 
開發者ID:paul-io,項目名稱:momo-2,代碼行數:38,代碼來源:WebServer.java

示例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()));
}
 
開發者ID:tankerkiller125,項目名稱:DiscordDevRant,代碼行數:22,代碼來源:DevRant.java

示例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);
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:20,代碼來源:GameClient.java

示例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;
}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:28,代碼來源:HttpClientUtil.java

示例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;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:17,代碼來源:Entry.java

示例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, "");
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:AuthorizeHelper.java

示例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;
}
 
開發者ID:SimpleMessageNotification,項目名稱:smn-sdk-java,代碼行數:22,代碼來源:ListSmsCallbackEventRequest.java

示例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;
}
 
開發者ID:SShineTeam,項目名稱:Huochexing12306,代碼行數:18,代碼來源:HttpUtil.java

示例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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:URIBuilder.java


注:本文中的org.apache.http.NameValuePair類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。