当前位置: 首页>>代码示例>>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;未经允许,请勿转载。