Java Code Examples for org.apache.commons.httpclient.methods.GetMethod#getResponseCharSet()

The following examples show how to use org.apache.commons.httpclient.methods.GetMethod#getResponseCharSet() . 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: HttpCommonClient.java    From openrasp-testcases with MIT License 6 votes vote down vote up
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {
        String urlString = req.getParameter("url");
        if (urlString != null) {
            HttpClient httpClient = new HttpClient();
            GetMethod getMethod = new GetMethod(urlString);
            httpClient.executeMethod(getMethod);
            String charSet = getMethod.getResponseCharSet();
            byte[] responseBody = getMethod.getResponseBody();
            resp.getWriter().println("response:\r\n" + new String(responseBody, charSet));
        }
    } catch (IOException e) {
        resp.getWriter().println(e);
    }
}
 
Example 2
Source File: HttpClientUtil.java    From javabase with Apache License 2.0 6 votes vote down vote up
/**
 * 向目标发出一个GET请求并得到响应数据
 * @param url
 *            目标
 * @param params
 *            参数集合
 * @param timeout
 *            超时时间
 * @return 响应数据
 * @throws IOException 
 */
public static String sendGet(String url, Map<String, String> params, int timeout) throws Exception {
	GetMethod method = new GetMethod(url);
	if (params != null) {
		method.setQueryString(getQueryString(params));
	}
	byte[] content;
	String text = null, charset = null;
	try {
		content = executeMethod(method, timeout);
		charset = method.getResponseCharSet();
		text = new String(content, charset);
	} finally {
		method.releaseConnection();
	}
	return text;
}
 
Example 3
Source File: AbstractSolrAdminHTTPClient.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Executes an action or a command in SOLR using REST API 
 * 
 * @param httpClient HTTP Client to be used for the invocation
 * @param url Complete URL of SOLR REST API Endpoint
 * @return A JSON Object including SOLR response
 * @throws UnsupportedEncodingException
 */
protected JSONObject getOperation(HttpClient httpClient, String url) throws UnsupportedEncodingException 
{

    GetMethod get = new GetMethod(url);
    
    try {
        
        httpClient.executeMethod(get);
        if(get.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || get.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY)
        {
            Header locationHeader = get.getResponseHeader("location");
            if (locationHeader != null)
            {
                String redirectLocation = locationHeader.getValue();
                get.setURI(new URI(redirectLocation, true));
                httpClient.executeMethod(get);
            }
        }
        if (get.getStatusCode() != HttpServletResponse.SC_OK)
        {
            throw new LuceneQueryParserException("Request failed " + get.getStatusCode() + " " + url.toString());
        }

        Reader reader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), get.getResponseCharSet()));
        JSONObject json = new JSONObject(new JSONTokener(reader));
        return json;
        
    }
    catch (IOException | JSONException e) 
    {
        throw new AlfrescoRuntimeException(e.getMessage(), e);
    } 
    finally 
    {
        get.releaseConnection();
    }
}
 
Example 4
Source File: TestRailClient.java    From testrail-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
private TestRailResponse httpGetInt(String path) throws IOException {
    TestRailResponse result;
    GetMethod get = new GetMethod(host + "/" + path);
    HttpClient httpclient = setUpHttpClient(get);

    try {
        Integer status = httpclient.executeMethod(get);
        String body = new String(get.getResponseBody(), get.getResponseCharSet());
        result = new TestRailResponse(status, body);
    } finally {
        get.releaseConnection();
    }

    return result;
}