org.apache.http.NameValuePair Java Examples
The following examples show how to use
org.apache.http.NameValuePair.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: URLEncodedUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
/** * Adds all parameters within the Scanner to the list of <code>parameters</code>. * For example,a scanner containing the string <code>a=1&b=2&c=3</code> would * add the {@link org.apache.http.NameValuePair NameValuePairs} a=1, b=2, and c=3 to the * list of parameters. * * @param parameters List to add parameters to. * @param scanner Input that contains the parameters to parse. */ public static void parse( final List<NameValuePair> parameters, final Scanner scanner) { scanner.useDelimiter(PARAMETER_SEPARATOR); while (scanner.hasNext()) { String name = null; String value = null; String token = scanner.next(); int i = token.indexOf(NAME_VALUE_SEPARATOR); if (i != -1) { name = token.substring(0, i).trim(); value = token.substring(i + 1).trim(); } else { name = token.trim(); } parameters.add(new BasicNameValuePair(name, value)); } }
Example #2
Source File: CaiPiaoHttpUtils.java From ZTuoExchange_framework with MIT License | 6 votes |
/** * 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; charset=UTF-8"); request.setEntity(formEntity); } return httpClient.execute(request); }
Example #3
Source File: MainActivity.java From android-advanced-light with MIT License | 6 votes |
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(); } }
Example #4
Source File: LogoutAppServiceImpl.java From web-sso with Apache License 2.0 | 6 votes |
/** * 请求某个URL,带着参数列表。 * @param url * @param nameValuePairs * @return * @throws ClientProtocolException * @throws IOException */ protected String requestUrl(String url, List<NameValuePair> nameValuePairs) throws ClientProtocolException, IOException { HttpPost httpPost = new HttpPost(url); if(nameValuePairs!=null && nameValuePairs.size()>0){ httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } CloseableHttpResponse response = httpClient.execute(httpPost); try { if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); String content = EntityUtils.toString(entity); EntityUtils.consume(entity); return content; } else{ logger.warn("request the url: "+url+" , but return the status code is "+response.getStatusLine().getStatusCode()); return null; } } finally{ response.close(); } }
Example #5
Source File: ExplorerWebSocketServer.java From Explorer with Apache License 2.0 | 6 votes |
private String postQueryDatavis(String query) throws IOException { HttpClient httpclient = HttpClients.createDefault(); HttpPost httppost = new HttpPost("http://localhost:9000/dataviews"); String responseString = ""; // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(3); params.add(new BasicNameValuePair("name", query)); params.add(new BasicNameValuePair("query", query)); params.add(new BasicNameValuePair("iDataSource", "1")); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); //Execute and get the response. HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); try { responseString = IOUtils.toString(instream); } finally { instream.close(); } } return responseString; }
Example #6
Source File: ApiRequestService.java From ticket with GNU General Public License v3.0 | 6 votes |
public String uamauthclient(String userName, String tk) { HttpUtil httpUtil = UserTicketStore.httpUtilStore.get(userName); HttpPost httpPost = new HttpPost(apiConfig.getUamauthclient()); List<NameValuePair> formparams = new ArrayList<>(); formparams.add(new BasicNameValuePair("tk", tk)); UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formparams, Consts.UTF_8); httpPost.setEntity(urlEncodedFormEntity); Gson jsonResult = new Gson(); String response = httpUtil.post(httpPost); Map rsmap = jsonResult.fromJson(response, Map.class); if ("0.0".equals(rsmap.getOrDefault("result_code", "").toString())) { UserTicketStore.httpUtilStore.put(userName, httpUtil); return rsmap.get("apptk").toString(); } return null; }
Example #7
Source File: APKExpansionPolicy.java From Klyph with MIT License | 6 votes |
private Map<String, String> decodeExtras(String extras) { Map<String, String> results = new HashMap<String, String>(); try { URI rawExtras = new URI("?" + extras); List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8"); for (NameValuePair item : extraList) { String name = item.getName(); int i = 0; while (results.containsKey(name)) { name = item.getName() + ++i; } results.put(name, item.getValue()); } } catch (URISyntaxException e) { Log.w(TAG, "Invalid syntax error while decoding extras data from server."); } return results; }
Example #8
Source File: GameClient.java From appinventor-extensions with Apache License 2.0 | 6 votes |
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); }
Example #9
Source File: SmartUriAdapter.java From rya with Apache License 2.0 | 6 votes |
private static IRI createTypePropertiesUri(final ImmutableMap<RyaIRI, ImmutableMap<RyaIRI, Property>> typeProperties) throws SmartUriException { final List<NameValuePair> nameValuePairs = new ArrayList<>(); for (final Entry<RyaIRI, ImmutableMap<RyaIRI, Property>> typeProperty : typeProperties.entrySet()) { final RyaIRI type = typeProperty.getKey(); final Map<RyaIRI, Property> propertyMap = typeProperty.getValue(); final IRI typeUri = createIndividualTypeWithPropertiesUri(type, propertyMap); final String keyString = type.getDataType().getLocalName(); final String valueString = typeUri.getLocalName(); nameValuePairs.add(new BasicNameValuePair(keyString, valueString)); } final URIBuilder uriBuilder = new URIBuilder(); uriBuilder.addParameters(nameValuePairs); String uriString; try { final java.net.URI uri = uriBuilder.build(); final String queryString = uri.getRawSchemeSpecificPart(); uriString = "urn:test" + queryString; } catch (final URISyntaxException e) { throw new SmartUriException("Unable to create type properties for the Smart URI", e); } return VF.createIRI(uriString); }
Example #10
Source File: RESTSpewer.java From extract with MIT License | 6 votes |
@Override public void write(final TikaDocument tikaDocument) throws IOException { final HttpPut put = new HttpPut(uri.resolve(tikaDocument.getId())); final List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair(fields.forId(), tikaDocument.getId())); params.add(new BasicNameValuePair(fields.forPath(), tikaDocument.getPath().toString())); params.add(new BasicNameValuePair(fields.forText(), toString(tikaDocument.getReader()))); if (outputMetadata) { parametrizeMetadata(tikaDocument.getMetadata(), params); } put.setEntity(new UrlEncodedFormEntity(params, StandardCharsets.UTF_8)); put(put); }
Example #11
Source File: UploadBoxUploaderPlugin.java From neembuu-uploader with GNU General Public License v3.0 | 6 votes |
public static void loginUploadBox() throws Exception { HttpParams params = new BasicHttpParams(); params.setParameter( "http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6"); DefaultHttpClient httpclient = new DefaultHttpClient(params); System.out.println("Trying to log in to uploadbox.com"); HttpPost httppost = new HttpPost("http://www.uploadbox.com/en"); httppost.setHeader("Cookie", sidcookie); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("login", "")); formparams.add(new BasicNameValuePair("passwd", "")); formparams.add(new BasicNameValuePair("ac", "auth")); formparams.add(new BasicNameValuePair("back", "")); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8"); httppost.setEntity(entity); HttpResponse httpresponse = httpclient.execute(httppost); HttpEntity resEntity = httpresponse.getEntity(); System.out.println(httpresponse.getStatusLine()); }
Example #12
Source File: AliHttpUtils.java From charging_pile_cloud with MIT License | 6 votes |
/** * 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; charset=UTF-8"); request.setEntity(formEntity); } return httpClient.execute(request); }
Example #13
Source File: SimpleRestClient.java From canvas-api with GNU Lesser General Public License v3.0 | 6 votes |
private static List<NameValuePair> convertParameters(final Map<String, List<String>> parameterMap) { final List<NameValuePair> params = new ArrayList<>(); if (parameterMap == null) { return params; } for (final Map.Entry<String, List<String>> param : parameterMap.entrySet()) { final String key = param.getKey(); if(param.getValue() == null || param.getValue().isEmpty()) { params.add(new BasicNameValuePair(key, null)); LOG.debug("key: " + key + "\tempty value"); } for (final String value : param.getValue()) { params.add(new BasicNameValuePair(key, value)); LOG.debug("key: "+ key +"\tvalue: " + value); } } return params; }
Example #14
Source File: ActionRunner.java From curly with Apache License 2.0 | 6 votes |
private void addPostParams(HttpEntityEnclosingRequestBase request) throws UnsupportedEncodingException { final MultipartEntityBuilder multipartBuilder = MultipartEntityBuilder.create(); List<NameValuePair> formParams = new ArrayList<>(); postVariables.forEach((name, values) -> values.forEach(value -> { if (multipart) { if (value.startsWith("@")) { File f = new File(value.substring(1)); multipartBuilder.addBinaryBody(name, f, ContentType.DEFAULT_BINARY, f.getName()); } else { multipartBuilder.addTextBody(name, value); } } else { formParams.add(new BasicNameValuePair(name, value)); } })); if (multipart) { request.setEntity(multipartBuilder.build()); } else { request.setEntity(new UrlEncodedFormEntity(formParams)); } }
Example #15
Source File: GoogleAnalyticsDataPublisher.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * Use this method to publish using POST. * @param payload - use the buildPayload method to retrieve NameValuePair to use as payload here. * @param userAgent - set the userAgent - this can be overridden if userAgentOverride (ua) is set in payload * @param useSSL - to publish using HTTPS, set this value to true. * @return */ public static boolean publishPOST(List<NameValuePair> payload, String userAgent, boolean useSSL) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(getURI(useSSL)); post.setHeader(GoogleAnalyticsConstants.HTTP_HEADER_USER_AGENT, userAgent); try { post.setEntity(new UrlEncodedFormEntity(payload)); HttpResponse response = client.execute(post); if((response.getStatusLine().getStatusCode() == 200) && (response.getFirstHeader(GoogleAnalyticsConstants.HTTP_HEADER_CONTENT_TYPE).getValue() .equals(GoogleAnalyticsConstants.RESPONSE_CONTENT_TYPE))) { return true; } return false; } catch (IOException e) { return false; } }
Example #16
Source File: Identity.java From raccoon4 with Apache License 2.0 | 6 votes |
private static Map<String, String> doPost(HttpClient client, List<NameValuePair> params) throws ClientProtocolException, IOException { HttpPost httppost = new HttpPost(LOGIN_URL); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse response = client.execute(httppost); Map<String, String> map = parseContent(response.getEntity().getContent()); if (response.getStatusLine().getStatusCode() == 200) { return map; } if (map.containsKey("Error")) { throw new ClientProtocolException(map.get("Error")); } throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); }
Example #17
Source File: MyClawer.java From java-Crawler with MIT License | 6 votes |
public static synchronized void printHot(String u) throws Exception { HttpHost httpHost = new HttpHost( "60.195.17.240",3128); HttpPost httpPost = new HttpPost(u); httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36"); List<NameValuePair> list = new ArrayList<NameValuePair>(); list.add(new BasicNameValuePair("params", "RlBC7U1bfy/boPwg9ag7/a7AjkQOgsIfd+vsUjoMY2tyQCPFgnNoxHeCY+ZuHYqtM1zF8DWIBwJWbsCOQ6ZYxBiPE3bk+CI1U6Htoc4P9REBePlaiuzU4M3rDAxtMfNN3y0eimeq3LVo28UoarXs2VMWkCqoTXSi5zgKEKbxB7CmlBJAP9pn1aC+e3+VOTr0")); list.add(new BasicNameValuePair("encSecKey", "76a0d8ff9f6914d4f59be6b3e1f5d1fc3998317195464f00ee704149bc6672c587cd4a37471e3a777cb283a971d6b9205ce4a7187e682bdaefc0f225fb9ed1319f612243096823ddec88b6d6ea18f3fec883d2489d5a1d81cb5dbd0602981e7b49db5543b3d9edb48950e113f3627db3ac61cbc71d811889d68ff95d0eba04e9")); httpPost.setEntity(new UrlEncodedFormEntity(list)); CloseableHttpResponse response = closeableHttpClient.execute(httpPost); HttpEntity entity = response.getEntity(); String ux = EntityUtils.toString(entity, "utf-8"); //System.out.println(ux); ArrayList<String> s = getBook(ux); if(s.size()!=0) { System.out.println(Thread.currentThread().getName() + " ::: " + "目标:" + u); randomAccessFile.write((Thread.currentThread().getName() + " ::: " + "目标:" + u+"\r\n").getBytes()); } for (int i = 0; i < s.size(); i++) { String[] arr = s.get(i).split("\""); System.out.println(" "+arr[2]); randomAccessFile.write((arr[2]+"\r\n").getBytes()); } }
Example #18
Source File: HttpClientInterceptorTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testHttpRequestIsAttachedSuccessfully() throws IOException { Header entityContentTypeHeader = mockContentTypeHeader(); Header[] headers = {entityContentTypeHeader}; when(entityContentTypeHeader.getElements()[0].getParameters()).thenReturn(new NameValuePair[0]).getMock(); testHttpRequestIsAttachedSuccessfully(headers, entityContentTypeHeader); }
Example #19
Source File: XMLUtil.java From common-project with Apache License 2.0 | 5 votes |
/** * 请求参数转换xml * @param params * @return */ public static String toXml(List<NameValuePair> params) { StringBuilder sb = new StringBuilder(); sb.append("<xml>"); for (int i = 0; i < params.size(); i++) { sb.append("<" + params.get(i).getName() + ">"); sb.append(params.get(i).getValue()); sb.append("</" + params.get(i).getName() + ">"); } sb.append("</xml>"); return sb.toString(); }
Example #20
Source File: WebHttpUtils.java From frpMgr with MIT License | 5 votes |
public static String post(String url, Map<String, String> nameValuePair) { String data = null; logger.debug(">>>请求地址:{},参数:{}", url, JSON.toJSONString(nameValuePair)); try { HttpPost httpPost = new HttpPost(url); if (nameValuePair != null) { List<NameValuePair> nvps = new ArrayList<NameValuePair>(); for (Map.Entry<String, String> entry : nameValuePair.entrySet()) { nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } httpPost.setEntity(new UrlEncodedFormEntity(nvps, ENCODE)); } try (CloseableHttpResponse response = httpClient.execute(httpPost)) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity entity = response.getEntity(); data = EntityUtils.toString(entity); logger.debug(">>>返回结果:{}", data); EntityUtils.consume(entity); } else { httpPost.abort(); } } } catch (Exception e) { logger.error(">>>请求异常", e); } return data; }
Example #21
Source File: WorkSpaceAdapter.java From emissary with Apache License 2.0 | 5 votes |
/** * Outbound open tells a remote WorkSpace to start pulling data * * @param place the remote place to contact * @param space the location of the work distributor */ public EmissaryResponse outboundOpenWorkSpace(final String place, final String space) { final String placeUrl = KeyManipulator.getServiceHostURL(place); final HttpPost method = new HttpPost(placeUrl + CONTEXT + "/WorkSpaceClientOpenWorkSpace.action"); final List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair(CLIENT_NAME, place)); nvps.add(new BasicNameValuePair(SPACE_NAME, space)); method.setEntity(new UrlEncodedFormEntity(nvps, java.nio.charset.Charset.defaultCharset())); // set a timeout in case a node is unresponsive method.setConfig(RequestConfig.custom().setConnectTimeout(60000).setSocketTimeout(60000).build()); return send(method); }
Example #22
Source File: UserSigninParser.java From clouddisk with MIT License | 5 votes |
@Override public HttpPost initRequest(final UserSigninParameter parameter) { final HttpPost request = new HttpPost(getRequestUri()); final List<NameValuePair> data = new ArrayList<>(4); data.add(new BasicNameValuePair(CONST.AJAX_KEY, CONST.AJAX_VAL)); data.add(new BasicNameValuePair(CONST.METHOD_KEY, UserSizeConst.METHOD_VAL)); data.add(new BasicNameValuePair("t", TimeUtil.getTimeLenth(10))); request.setEntity(new UrlEncodedFormEntity(data, Consts.UTF_8)); return request; }
Example #23
Source File: MartiDiceRoller.java From triplea with GNU General Public License v3.0 | 5 votes |
@Override public String postRequest( final int max, final int numDice, final String subjectMessage, final String gameId) throws IOException { final String normalizedGameId = gameId.isBlank() ? "TripleA" : gameId; String message = normalizedGameId + ":" + subjectMessage; if (message.length() > MESSAGE_MAX_LENGTH) { message = message.substring(0, MESSAGE_MAX_LENGTH - 1); } try (CloseableHttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new AdvancedRedirectStrategy()).build()) { final HttpPost httpPost = new HttpPost(DICE_ROLLER_PATH); final List<NameValuePair> params = ImmutableList.of( new BasicNameValuePair("numdice", String.valueOf(numDice)), new BasicNameValuePair("numsides", String.valueOf(max)), new BasicNameValuePair("subject", message), new BasicNameValuePair("roller", getToAddress()), new BasicNameValuePair("gm", getCcAddress())); httpPost.setEntity(new UrlEncodedFormEntity(params, StandardCharsets.UTF_8)); httpPost.addHeader("User-Agent", "triplea/" + ClientContext.engineVersion()); final HttpHost hostConfig = new HttpHost(diceRollerUri.getHost(), diceRollerUri.getPort(), diceRollerUri.getScheme()); HttpProxy.addProxy(httpPost); try (CloseableHttpResponse response = httpClient.execute(hostConfig, httpPost)) { return EntityUtils.toString(response.getEntity()); } } }
Example #24
Source File: HttpRequestConfig.java From bbs with GNU Affero General Public License v3.0 | 5 votes |
/** * 执行post提交 * @param url 提交的URL * @param paramMap 参数集合 * @return * @throws IOException */ public HttpResult doPost(String url, Map<String, String> paramMap) throws IOException { HttpPost httpPost = new HttpPost(url); // httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); //设置请求参数 httpPost.setConfig(requestConfig); if (paramMap != null) { List<NameValuePair> parameters = new ArrayList<NameValuePair>(); for (String s : paramMap.keySet()) { parameters.add(new BasicNameValuePair(s, paramMap.get(s))); } //构建一个form表单式的实体 UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(parameters, Charset.forName("UTF-8")); //将请求实体放入到httpPost中 httpPost.setEntity(formEntity); } //创建httpClient对象 CloseableHttpResponse response = null; try { //执行请求 response = httpClient.execute(httpPost); return new HttpResult(response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(),"UTF-8")); } catch (IOException e) { throw e; } finally { if (response != null) { response.close(); } } }
Example #25
Source File: HttpClientUtils.java From JobX with Apache License 2.0 | 5 votes |
public static String httpGetRequest(String url, Map<String, Object> headers, Map<String, Object> params) throws URISyntaxException { URIBuilder ub = new URIBuilder(); ub.setPath(url); ArrayList<NameValuePair> pairs = covertParams2NVPS(params); ub.setParameters(pairs); HttpGet httpGet = new HttpGet(ub.build()); for (Map.Entry<String, Object> param : headers.entrySet()) { httpGet.addHeader(param.getKey(), String.valueOf(param.getValue())); } return getResult(httpGet); }
Example #26
Source File: FileSearchParser.java From clouddisk with MIT License | 5 votes |
@Override public HttpPost initRequest(final FileSearchParameter parameter) { final HttpPost request = new HttpPost(getRequestUri()); final List<NameValuePair> data = new ArrayList<>(5); data.add(new BasicNameValuePair(CONST.KEY_NAME, parameter.getKey())); data.add(new BasicNameValuePair(CONST.ISFPATH_NAME, "1")); data.add(new BasicNameValuePair(CONST.PAGE_NAME, String.valueOf(parameter.getPage()))); data.add(new BasicNameValuePair(CONST.PAGE_SIZE_NAME, String.valueOf(parameter.getPage_size()))); data.add(new BasicNameValuePair(CONST.AJAX_KEY, CONST.AJAX_VAL)); request.setEntity(new UrlEncodedFormEntity(data, Consts.UTF_8)); return request; }
Example #27
Source File: WebAppProxyServlet.java From sylph with Apache License 2.0 | 5 votes |
protected void doGet1(HttpServletRequest req, HttpServletResponse resp) throws IOException { try { final String remoteUser = req.getRemoteUser(); final String pathInfo = req.getPathInfo(); String[] parts = pathInfo.split("/", 3); checkArgument(parts.length >= 2, remoteUser + " gave an invalid proxy path " + pathInfo); //parts[0] is empty because path info always starts with a / String jobIdOrRunId = parts[1]; String rest = parts.length > 2 ? parts[2] : ""; URI trackingUri = new URI(getJobUrl(jobIdOrRunId)); // Append the user-provided path and query parameter to the original // tracking url. String query = req.getQueryString() == null ? "" : req.getQueryString(); List<NameValuePair> queryPairs = URLEncodedUtils.parse(query, null); UriBuilder builder = UriBuilder.fromUri(trackingUri); for (NameValuePair pair : queryPairs) { builder.queryParam(pair.getName(), pair.getValue()); } URI toFetch = builder.path(rest).build(); proxyLink(req, resp, toFetch, null); } catch (URISyntaxException e) { throw new IOException(e); } }
Example #28
Source File: HttpDataService.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected URI getRequestURI(Map<String, Object> parameters) { String url = getURL(parameters); if (url == null) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_NO_HTTP_URL_SET, (Object[])null); } try { URIBuilder uriBuilder = new URIBuilder(url); List<NameValuePair> urlParameters = collectUrlParameters(parameters); if (!urlParameters.isEmpty()) { uriBuilder.addParameters(urlParameters); } URI uri = uriBuilder.build(); if (log.isDebugEnabled()) { log.debug("request URI " + uri); } return uri; } catch (URISyntaxException e) { throw new JRRuntimeException(e); } }
Example #29
Source File: NovelListActivity.java From light-novel-library_Wenku8_Android with GNU General Public License v2.0 | 5 votes |
private void loadSearchResultList() { // the result is just 10 records, so don't need "isLoading" List<NameValuePair> targVarList = new ArrayList<NameValuePair>(); if (plus == 1) { targVarList.add(Wenku8Interface.searchNovelByNovelName(name, GlobalConfig.getFetchLanguage())); } else if (plus == 2) { targVarList.add(Wenku8Interface.searchNovelByAuthorName(name, GlobalConfig.getFetchLanguage())); } isSearching = true; final asyncSearchTask ast = new asyncSearchTask(); ast.execute(targVarList); pDialog = new ProgressDialog(parentActivity); pDialog.setTitle(getResources().getString(R.string.search_ing)); pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pDialog.setCancelable(true); pDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { // TODO Auto-generated method stub isSearching = false; if (pDialog != null) pDialog.dismiss(); pDialog = null; } }); pDialog.setMessage(getResources().getString(R.string.search_fetching)); pDialog.setProgress(0); pDialog.setMax(1); pDialog.show(); return; }
Example #30
Source File: HttpInvoker.java From certificate-transparency-java with Apache License 2.0 | 5 votes |
/** * Makes an HTTP GET method call to the given URL with the provides parameters. * * @param url URL for GET method. * @param params query parameters. * @return Server's response body. */ public String makeGetRequest(String url, List<NameValuePair> params) { try (CloseableHttpClient httpClient = httpClientBuilder.build()) { String paramsStr = ""; if (params != null) { paramsStr = "?" + URLEncodedUtils.format(params, "UTF-8"); } HttpGet get = new HttpGet(url + paramsStr); get.addHeader("Content-Type", "application/json; charset=utf-8"); return httpClient.execute(get, new BasicResponseHandler()); } catch (IOException e) { throw new LogCommunicationException("Error making GET request to " + url, e); } }