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


Java UrlEncodedFormEntity類代碼示例

本文整理匯總了Java中org.apache.http.client.entity.UrlEncodedFormEntity的典型用法代碼示例。如果您正苦於以下問題:Java UrlEncodedFormEntity類的具體用法?Java UrlEncodedFormEntity怎麽用?Java UrlEncodedFormEntity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UrlEncodedFormEntity類屬於org.apache.http.client.entity包,在下文中一共展示了UrlEncodedFormEntity類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: PostParam

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
private synchronized void PostParam(String url, List<BasicNameValuePair> parameters) throws Exception {
    HttpPost post = new HttpPost(url);
    String result = "";
    try {
        post.setEntity(new UrlEncodedFormEntity(parameters, "utf-8"));
        HttpResponse response = client.execute(post);
        HttpEntity httpEntity = response.getEntity();
        result = EntityUtils.toString(httpEntity, "utf-8");
    } catch (java.io.IOException e) {
        e.printStackTrace();
    } finally {

        JSONObject jsonObject = new JSONObject(result);
        String status = jsonObject.getString("status");
        if (!status.equals("success")) {
            throw new Exception(jsonObject.getString("msg"));
        }
        System.out.println(status);
    }
}
 
開發者ID:zackszhu,項目名稱:hack_sjtu_2017,代碼行數:21,代碼來源:HttpHandler.java

示例2: report

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
/**
 * 報工
 * 
 */
public boolean report() {
	HttpPost post = new HttpPost(Api.reportUrl);
	try {
		post.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8));
		HttpResponse resp = client.execute(post);
		JSONObject jo = JSONObject.parseObject(EntityUtils.toString(resp.getEntity()));
		// 報工成功,返回json結構的報文{"data" : [ {},{}...],"success" : true}
		if (jo.getBooleanValue("success")) {
			return true;
		}
		logger.warn(jo.getString("error"));
	} catch (Exception e) {
		logger.error("報工異常:", e);
	}
	return false;
}
 
開發者ID:ichatter,項目名稱:dcits-report,代碼行數:21,代碼來源:UserService.java

示例3: post

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的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:mumucommon,項目名稱:mumu-core,代碼行數:28,代碼來源:HttpClientUtil.java

示例4: postForRefreshAndAccessToken

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的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

示例5: doPost

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
/**
 * post form
 *
 * @param host
 * @param path
 * @param method
 * @param headers
 * @param querys
 * @param bodys
 * @return
 * @throws Exception
 */
public static HttpResponse doPost(String host, String path, String method,
                                  Map<String, String> headers,
                                  Map<String, String> querys,
                                  Map<String, String> bodys)
        throws Exception {
    HttpClient httpClient = wrapClient(host);

    HttpPost request = new HttpPost(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
        request.addHeader(e.getKey(), e.getValue());
    }

    if (bodys != null) {
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();

        for (String key : bodys.keySet()) {
            nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
        }
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
        formEntity.setContentType("application/x-www-form-urlencoded");

        request.setEntity(formEntity);
    }

    return httpClient.execute(request);
}
 
開發者ID:JiaXiaohei,項目名稱:elasticjob-stock-push,代碼行數:39,代碼來源:HttpUtils.java

示例6: call

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
public String call(final String vast, final String adid, final String zoneid) {
	final List<NameValuePair> nameValuePairs = new ArrayList<>();
	nameValuePairs.add(new BasicNameValuePair("adid", adid));
	nameValuePairs.add(new BasicNameValuePair("zoneid", zoneid));
	nameValuePairs.add(new BasicNameValuePair("vast", vast));

	try {
		return jsonPostConnector.connect(new UrlEncodedFormEntity(nameValuePairs, StandardCharsets.UTF_8), new HttpPost(endPoint));
	} catch (final BidProcessingException e) {
		log.error(e.getMessage());
	}
	return null;
}
 
開發者ID:ad-tech-group,項目名稱:openssp,代碼行數:14,代碼來源:VastResolverBroker.java

示例7: login

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
/**
 * 登陸報工係統
 */
public boolean login() {
	HttpPost post = new HttpPost(Api.loginUrl);
	List<NameValuePair> params = new ArrayList<NameValuePair>();
	params.add(new BasicNameValuePair("username", SessionUtil.getUsername()));
	params.add(new BasicNameValuePair("password", SessionUtil.getPassword()));
	try {
		post.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8));
		HttpResponse resp = client.execute(post);// 登陸
		String charset = HttpHeaderUtil.getResponseCharset(resp);
		String respHtml = StringUtil.removeEmptyLine(resp.getEntity().getContent(), charset == null ? "utf-8" : charset);

		Document doc = Jsoup.parse(respHtml);
		Elements titles = doc.getElementsByTag("TITLE");
		for (Element title : titles) {
			if (title.hasText() && title.text().contains("Success")) {
				return true;// 登陸成功
			}
		}
	} catch (Exception e) {
		logger.error("登陸失敗:", e);
	}
	return false;
}
 
開發者ID:ichatter,項目名稱:dcits-report,代碼行數:27,代碼來源:UserService.java

示例8: sendPost

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
public void sendPost(String url, String urlParameters) throws Exception {
    HttpClient client = getHttpClient();
    HttpPost request = new HttpPost(url);
    request.addHeader("User-Agent", "Mozilla/5.0");

    List<NameValuePair> valuePairs = new ArrayList<NameValuePair>();
    String[] s = urlParameters.split("&");
    for (int i = 0; i < s.length; i++) {
        String g = s[i];
        valuePairs.add(new BasicNameValuePair(g.substring(0,g.indexOf("=")), g.substring(g.indexOf("=")+1)));
    }

    request.setEntity(new UrlEncodedFormEntity(valuePairs));
    HttpResponse response = client.execute(request);
    System.out.println("Response Code: " + response.getStatusLine().getStatusCode());

    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    StringBuffer result = new StringBuffer();
    String responseLine;
    while ((responseLine = bufferedReader.readLine()) != null) {
        result.append(responseLine);
    }

    System.out.println("Response: " + result.toString());
}
 
開發者ID:avedensky,項目名稱:JavaRushTasks,代碼行數:26,代碼來源:Solution.java

示例9: POST

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
public static Future<HttpResponse> POST(String url, FutureCallback<HttpResponse> callback,
        List<NameValuePair> params, String encoding, Map<String, String> headers) {
    HttpPost post = new HttpPost(url);
    headers.forEach((key, value) -> {
        post.setHeader(key, value);
    });
    HttpEntity entity = new UrlEncodedFormEntity(params, HttpClientUtil.getEncode(encoding));
    post.setEntity(entity);
    return HTTP_CLIENT.execute(post, callback);
}
 
開發者ID:jiumao-org,項目名稱:wechat-mall,代碼行數:11,代碼來源:AsynHttpClient.java

示例10: post

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
private String post(String url, List<NameValuePair> nvps) throws IOException{
	CloseableHttpClient httpclient = connectionPoolManage.getHttpClient();
	
	HttpPost httpPost = new HttpPost(url);
	
	if(nvps != null)
		httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
	
	CloseableHttpResponse response = httpclient.execute(httpPost);
	
	String result = null;
	if(response.getStatusLine().getStatusCode() == 200){
		HttpEntity entity = response.getEntity();
		result = EntityUtils.toString(entity);
	}
	
	httpclient.close();
	
	return result;
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:21,代碼來源:MockTestFilter.java

示例11: createModule

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
/**
 * Creates a module for a specific customer
 *
 * @param customerName the name of the customer
 * @param moduleName the name of the module to create
 * @return request object to check status codes and return values
 */
public Response createModule( String customerName, String moduleName )
{
	final HttpPost request = new HttpPost( this.yambasBase + "customers/" + customerName + "/modules" );
	setAuthorizationHeader( request );

	final List<NameValuePair> data = new ArrayList<NameValuePair>( );
	data.add( new BasicNameValuePair( "name", moduleName ) );

	try
	{
		request.setEntity( new UrlEncodedFormEntity( data ) );
		final HttpResponse response = this.client.execute( request );
		return new Response( response );
	}
	catch ( final IOException e )
	{
		e.printStackTrace( );
	}
	return null;
}
 
開發者ID:ApinautenGmbH,項目名稱:integration-test-helper,代碼行數:28,代碼來源:AomHttpClient.java

示例12: run

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
@Override
public void run() {
    try {
        BasicHttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, 500);
        HttpConnectionParams.setSoTimeout(httpParams, 500);

        HttpClient httpclient = new DefaultHttpClient(httpParams);

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("latitude", "" + latitude));
        params.add(new BasicNameValuePair("longitude", "" + longitude));
        params.add(new BasicNameValuePair("userid", userId));

        //服務器地址,指向Servlet
        HttpPost httpPost = new HttpPost(ServerUtil.SLUpdateLocation);

        final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "utf-8");//以UTF-8格式發送
        httpPost.setEntity(entity);
        //對提交數據進行編碼
        httpclient.execute(httpPost);
    } catch (Exception e) {

    }
}
 
開發者ID:838030195,項目名稱:DaiGo,代碼行數:26,代碼來源:LocationService.java

示例13: postSlackCommand

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
private void postSlackCommand(Map<String, String> params, String command, SlackMessageHandleImpl handle) {
    HttpClient client = getHttpClient();
    HttpPost request = new HttpPost(SLACK_API_HTTPS_ROOT + command);
    List<NameValuePair> nameValuePairList = new ArrayList<>();
    for (Map.Entry<String, String> arg : params.entrySet())
    {
        nameValuePairList.add(new BasicNameValuePair(arg.getKey(), arg.getValue()));
    }
    try
    {
        request.setEntity(new UrlEncodedFormEntity(nameValuePairList, "UTF-8"));
        HttpResponse response = client.execute(request);
        String jsonResponse = consumeToString(response.getEntity().getContent());
        LOGGER.debug("PostMessage return: " + jsonResponse);
        ParsedSlackReply reply = SlackJSONReplyParser.decode(parseObject(jsonResponse),this);
        handle.setReply(reply);
    }
    catch (Exception e)
    {
        // TODO : improve exception handling
        e.printStackTrace();
    }
}
 
開發者ID:riversun,項目名稱:slacklet,代碼行數:24,代碼來源:SlackWebSocketSessionImpl.java

示例14: useHttpClientPost

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
private void useHttpClientPost(String url) {
    HttpPost mHttpPost = new HttpPost(url);
    mHttpPost.addHeader("Connection", "Keep-Alive");
    try {
        HttpClient mHttpClient = createHttpClient();
        List<NameValuePair> postParams = new ArrayList<>();
        //要傳遞的參數
        postParams.add(new BasicNameValuePair("ip", "59.108.54.37"));
        mHttpPost.setEntity(new UrlEncodedFormEntity(postParams));
        HttpResponse mHttpResponse = mHttpClient.execute(mHttpPost);
        HttpEntity mHttpEntity = mHttpResponse.getEntity();
        int code = mHttpResponse.getStatusLine().getStatusCode();
        if (null != mHttpEntity) {
            InputStream mInputStream = mHttpEntity.getContent();
            String respose = converStreamToString(mInputStream);
            Log.d(TAG, "請求狀態碼:" + code + "\n請求結果:\n" + respose);
            mInputStream.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:henrymorgen,項目名稱:android-advanced-light,代碼行數:23,代碼來源:MainActivity.java

示例15: createDataEntity

import org.apache.http.client.entity.UrlEncodedFormEntity; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private HttpEntity createDataEntity(Object data) {
	try {
		if (data instanceof Map) {
			List<NameValuePair> params = new ArrayList<NameValuePair>(0);
			for (Entry<String, Object> entry : ((Map<String, Object>) data).entrySet()) {
				params.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString()));
			}
			return new UrlEncodedFormEntity(params, "UTF-8");
		} else {
			return new StringEntity(data.toString(), "UTF-8");
		}
	} catch (UnsupportedEncodingException e) {
		throw new RuntimeException("Unsupported encoding noticed. Error message: " + e.getMessage());
	}
}
 
開發者ID:Hi-Fi,項目名稱:httpclient,代碼行數:17,代碼來源:RestClient.java


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