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


Java BasicResponseHandler類代碼示例

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


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

示例1: notifyHunter

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
public String notifyHunter(byte[] content) throws IOException {
    try {
        String request = new String(content);
        SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build();
        HttpClient httpclient = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
        HttpPost httpPost = new HttpPost("https://api"+hunterDomain.substring(hunterDomain.indexOf("."))+"/api/record_injection");
        String json = "{\"request\": \""+request.replace("\\", "\\\\").replace("\"", "\\\"").replace("\r\n", "\\n")+"\", \"owner_correlation_key\": \""+hunterKey+"\", \"injection_key\": \""+injectKey+"\"}";
        StringEntity entity = new StringEntity(json);
        entity.setContentType("applicaiton/json");
        httpPost.setEntity(entity);
        HttpResponse response = httpclient.execute(httpPost);
        String responseString = new BasicResponseHandler().handleResponse(response);
        return responseString;
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) {
        
        Logger.getLogger(HunterRequest.class.getName()).log(Level.SEVERE, null, ex);
    }
    return "Error Notifying Probe Server!";
}
 
開發者ID:mystech7,項目名稱:Burp-Hunter,代碼行數:20,代碼來源:HunterRequest.java

示例2: getResponseAsString

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
public static Optional<String> getResponseAsString(HttpRequestBase httpRequest, HttpClient client) {
    Optional<String> result = Optional.empty();
    final int waitTime = 60000;
    try {
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(waitTime).setConnectTimeout(waitTime)
                .setConnectionRequestTimeout(waitTime).build();
        httpRequest.setConfig(requestConfig);
        result = Optional.of(client.execute(httpRequest, responseHandler));
    } catch (HttpResponseException httpResponseException) {
        LOG.error("getResponseAsString(): caught 'HttpResponseException' while processing request <{}> :=> <{}>", httpRequest,
                httpResponseException.getMessage());
    } catch (IOException ioe) {
        LOG.error("getResponseAsString(): caught 'IOException' while processing request <{}> :=> <{}>", httpRequest, ioe.getMessage());
    } finally {
        httpRequest.releaseConnection();
    }
    return result;
}
 
開發者ID:dockstore,項目名稱:write_api_service,代碼行數:20,代碼來源:ResourceUtilities.java

示例3: getToken

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
public AccessTokenDTO getToken(String code) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    AccessTokenDTO token = null;
    try {
        HttpPost httppost = new HttpPost("https://api.twitch.tv/kraken/oauth2/token" +
                "?client_id=" + Config.getCatalog().twitch.clientId +
                "&client_secret=" + Config.getCatalog().twitch.clientSecret +
                "&code=" + code +
                "&grant_type=authorization_code" +
                "&redirect_uri=" + Config.getCatalog().twitch.redirectUri);

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httppost, responseHandler);

        token = new Gson().fromJson(responseBody, AccessTokenDTO.class);
    } catch (IOException e) {
        TwasiLogger.log.error(e);
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
        httpclient.close();
    }
    return token;
}
 
開發者ID:Twasi,項目名稱:twasi-core,代碼行數:27,代碼來源:TwitchAPI.java

示例4: queryConfig

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
/**
 * 查詢配置
 */
public Map<String, String> queryConfig() {
    try {
        String resultStr = HTTP_CLIENT.execute(request, new BasicResponseHandler());
        FindPropertiesResult result = JSON.parseObject(resultStr, FindPropertiesResult.class);
        if (result == null) {
            throw new RuntimeException("請求配置中心失敗");
        }
        if (!result.isSuccess()) {
            throw new RuntimeException("從配置中心讀取配置失敗:" + result.getMessage());
        }
        return result.getProperties();
    } catch (IOException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 
開發者ID:zhongxunking,項目名稱:configcenter,代碼行數:19,代碼來源:ServerRequester.java

示例5: getText

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
public static String getText(String redirectLocation) {
    HttpGet httpget = new HttpGet(redirectLocation);
    // Create a response handler
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = "";
    try {
        responseBody = httpclient.execute(httpget, responseHandler);
    } catch (Exception e) {
        e.printStackTrace();
        responseBody = null;
    } finally {
        httpget.abort();
        // httpclient.getConnectionManager().shutdown();
    }
    return responseBody;
}
 
開發者ID:bluetata,項目名稱:crawler-jsoup-maven,代碼行數:17,代碼來源:CSDNLoginApater.java

示例6: main

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
public final static void main(String[] args) throws Exception {
    
    HttpClient httpclient = new DefaultHttpClient();

    HttpGet httpget = new HttpGet("http://www.google.com/"); 

    System.out.println("executing request " + httpget.getURI());

    // Create a response handler
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = httpclient.execute(httpget, responseHandler);
    System.out.println(responseBody);
    
    System.out.println("----------------------------------------");

    // When HttpClient instance is no longer needed, 
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();        
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:21,代碼來源:ClientWithResponseHandler.java

示例7: getResponseJsonObject

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
private JSONObject getResponseJsonObject(String httpMethod, String url, Object params) throws IOException, MtWmErrorException {

        HttpUriRequest httpUriRequest = null;
        String fullUrl = getBaseApiUrl() + url;
        List<NameValuePair> sysNameValuePairs = getSysNameValuePairs(fullUrl, params);
        List<NameValuePair> nameValuePairs = getNameValuePairs(params);
        if (HTTP_METHOD_GET.equals(httpMethod)) {
            sysNameValuePairs.addAll(nameValuePairs);
            HttpGet httpGet = new HttpGet(fullUrl + "?" + URLEncodedUtils.format(sysNameValuePairs, UTF_8));
            setRequestConfig(httpGet);
            httpUriRequest = httpGet;
        } else if (HTTP_METHOD_POST.equals(httpMethod)) {
            HttpPost httpPost = new HttpPost(fullUrl + "?" + URLEncodedUtils.format(sysNameValuePairs, UTF_8));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, UTF_8));
            setRequestConfig(httpPost);
            httpUriRequest = httpPost;
        }

        CloseableHttpResponse response = this.httpClient.execute(httpUriRequest);
        String resultContent = new BasicResponseHandler().handleResponse(response);
        JSONObject jsonObject = JSON.parseObject(resultContent);
        MtWmError error = MtWmError.fromJson(jsonObject);
        if (error != null) {
            logging(url, httpMethod, false, httpUriRequest.getURI() + "\nBody:" + JSON.toJSONString(params), resultContent);
            throw new MtWmErrorException(error.getErrorCode(), error.getErrorMsg());
        }
        logging(url, httpMethod, true, httpUriRequest.getURI() + "\nBody:" + JSON.toJSONString(params), resultContent);
        return jsonObject;
    }
 
開發者ID:kuangcao,項目名稱:meituanwaimai-sdk,代碼行數:30,代碼來源:BaseServiceImpl.java

示例8: makeBasicPostRequest

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
private static String makeBasicPostRequest(String path, JSONObject jsonObject, String token) throws Exception {
	DefaultHttpClient httpclient = getNewHttpClient();

	HttpPost httpPost = new HttpPost(path);


	StringEntity se = new StringEntity(jsonObject.toString());

	httpPost.setEntity(se);
	setBasicHeaders(httpPost, token);

	//Handles what is returned from the page
	ResponseHandler responseHandler = new BasicResponseHandler();
	String response = "{\"success\":\"false\"}";
	try {
		response = (String) httpclient.execute(httpPost, responseHandler);
	} catch (org.apache.http.client.HttpResponseException e) {
		e.printStackTrace(); // todo: retrieve status code and evaluate it
		Log.d("statusCode order Post", Integer.toString(e.getStatusCode()));
	}
	return response;
}
 
開發者ID:andserve,項目名稱:delivresh-android,代碼行數:23,代碼來源:AndroidHttpClientContainer.java

示例9: postImpex

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
/**
 * Send HTTP POST request to {@link #getEndpointUrl(), imports impex
 *
 * @param file
 *            file to be imported
 * @return import status message
 * @throws IOException
 * @throws HttpResponseException
 */
private String postImpex(final IFile file) throws HttpResponseException, IOException {
	final Map<String, String> parameters = new HashMap<>();
	final HttpPost postRequest = new HttpPost(getEndpointUrl() + ImpexImport.IMPEX_IMPORT_PATH);
	final RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(getTimeout()).build();
	
	parameters.put(ImpexImport.Parameters.ENCODING, getEncoding());
	parameters.put(ImpexImport.Parameters.SCRIPT_CONTENT, getContentOfFile(file));
	parameters.put(ImpexImport.Parameters.MAX_THREADS, ImpexImport.Parameters.MAX_THREADS_VALUE);
	parameters.put(ImpexImport.Parameters.VALIDATION_ENUM, ImpexImport.Parameters.VALIDATION_ENUM_VALUE);
	
	postRequest.setConfig(requestConfig);
	postRequest.addHeader(getxCsrfToken(), getCsrfToken());
	postRequest.setEntity(new UrlEncodedFormEntity(createParametersList(parameters)));
	
	final HttpResponse response = getHttpClient().execute(postRequest, getContext());
	final String responseBody = new BasicResponseHandler().handleResponse(response);
	
	return getImportStatus(responseBody);
}
 
開發者ID:SAP,項目名稱:hybris-commerce-eclipse-plugin,代碼行數:29,代碼來源:ImportManager.java

示例10: fetchCsrfTokenFromHac

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
/**
 * Send HTTP GET request to {@link #endpointUrl}, updates {@link #csrfToken}
 * token
 *
 * @return true if {@link #endpointUrl} is accessible
 * @throws IOException
 * @throws ClientProtocolException
 * @throws AuthenticationException 
 */
protected void fetchCsrfTokenFromHac() throws ClientProtocolException, IOException, AuthenticationException {
	final HttpGet getRequest = new HttpGet(getEndpointUrl());

	try {
		final HttpResponse response = httpClient.execute(getRequest, getContext());
		final String responseString = new BasicResponseHandler().handleResponse(response);
		csrfToken = getCsrfToken(responseString);
		
		if( StringUtil.isBlank(csrfToken) ) {
			throw new AuthenticationException(ErrorMessage.CSRF_TOKEN_CANNOT_BE_OBTAINED);
		}
	} catch (UnknownHostException error) {
		final String errorMessage = error.getMessage();
		final Matcher matcher = HACPreferenceConstants.HOST_REGEXP_PATTERN.matcher(getEndpointUrl());

		if (matcher.find() && matcher.group(1).equals(errorMessage)) {
			throw new UnknownHostException(
					String.format(ErrorMessage.UNKNOWN_HOST_EXCEPTION_MESSAGE_FORMAT, matcher.group(1)));
		}
		throw error;
	}
}
 
開發者ID:SAP,項目名稱:hybris-commerce-eclipse-plugin,代碼行數:32,代碼來源:AbstractHACCommunicationManager.java

示例11: updateExternalIPAddr

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
public static void updateExternalIPAddr() {
	nu_log.i("Retrieving external IP address.");
	CloseableHttpClient cli = HttpClients.createDefault();
	
	nu_log.d("IP retrieval URL = " + ip_retrieval_url);
	HttpGet req = new HttpGet(ip_retrieval_url);
	req.addHeader("User-Agent", "PacChat HTTP " + Main.VERSION);
	
	try {
		CloseableHttpResponse res = cli.execute(req);
		
		BasicResponseHandler handler = new BasicResponseHandler();
		external_ip = handler.handleResponse(res);
		nu_log.i("External IP address detected as: " + external_ip);
	} catch (IOException e) {
		nu_log.e("Error while retrieving external IP!");
		e.printStackTrace();
	}
}
 
開發者ID:Arccotangent,項目名稱:pacchat,代碼行數:20,代碼來源:NetUtils.java

示例12: getResponseByPost

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
public String getResponseByPost(String url,String encode,String[] params)throws Exception{
	httpPost = new HttpPost(url); 
	List<org.apache.http.NameValuePair> formParams = new ArrayList<org.apache.http.NameValuePair>();
	for(int i=0; i<params.length/2;i++){
		formParams.add(new BasicNameValuePair(params[i*2], params[i*2+1]));
	}
	HttpEntity entityForm = new UrlEncodedFormEntity(formParams, encode);
	httpPost.setEntity(entityForm);
	
	
	ResponseHandler<String> responseHandler = new BasicResponseHandler();
	
	
	content = httpClient.execute(httpPost, responseHandler);
	return content;
}
 
開發者ID:wufeisoft,項目名稱:ryf_mms2,代碼行數:17,代碼來源:RemoteAccessor.java

示例13: getResponseByProxy

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
public String getResponseByProxy(String url)throws Exception{
	httpClient = new DefaultHttpClient();
	
	do{
		HttpHost proxy = new HttpHost((String)getProxy().get(0), (Integer)getProxy().get(1));
		httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
		httpGet = new HttpGet(url); 
		ResponseHandler<String> responseHandler = new BasicResponseHandler();
		int count = 0;
		try{
				content = httpClient.execute(httpGet, responseHandler);
		}catch(Exception e){
			System.out.println("Remote accessed by proxy["+(String)getProxy().get(0)+":"+(Integer)getProxy().get(1)+"] had Error!Try next!");
		}
		count++;
		if(count>2){break;}
	}while(content.length()==0);
	return content;
}
 
開發者ID:wufeisoft,項目名稱:ryf_mms2,代碼行數:20,代碼來源:RemoteAccessor.java

示例14: postLine

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
private void postLine(String data) throws Exception {

        StringEntity postingString = new StringEntity(data);

        //System.out.println(data);
        httpPost.setEntity(postingString);
        //httpPost.setHeader("Content-type","plain/text");
        httpPost.setHeader("Content-type", "application/json");

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String resp = httpClient.execute(httpPost, responseHandler);

        //JSONObject jsonResp = new JSONObject(resp);
        //System.out.println(jsonResp);
        httpPost.releaseConnection();
    }
 
開發者ID:david618,項目名稱:Simulator,代碼行數:17,代碼來源:Elasticsearch3.java

示例15: getText

import org.apache.http.impl.client.BasicResponseHandler; //導入依賴的package包/類
private String getText(String redirectLocation) {  
    HttpGet httpget = new HttpGet(redirectLocation);  
    // Create a response handler  
    ResponseHandler<String> responseHandler = new BasicResponseHandler();  
    String responseBody = "";  
    try {  
        responseBody = httpclient.execute(httpget, responseHandler);  
    } catch (Exception e) {  
        e.printStackTrace();  
        responseBody = null;  
    } finally {  
        httpget.abort();  
        httpclient.getConnectionManager().shutdown();  
    }  
    return responseBody;  
}
 
開發者ID:MelissaChen15,項目名稱:Crawler2015,代碼行數:17,代碼來源:Login.java


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