protected GeocodeResponse request(final Gson gson, final String urlString) throws IOException { final GetMethod getMethod = new GetMethod(urlString); try { httpClient.executeMethod(getMethod); final Reader reader = new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()); return gson.fromJson(reader, GeocodeResponse.class); } finally { getMethod.releaseConnection(); } } }
import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.http.HttpStatus; import java.io.IOException; import java.io.InputStreamReader; HttpClient hc = new HttpClient(); GetMethod get = new GetMethod(uri); int status = hc.executeMethod(get); if (status != HttpStatus.SC_OK) throw new RuntimeException("http status " + status); ObjectMapper jsonParser = new ObjectMapper(new JsonFactory()); // we use an InputStreamReader with explicit charset to read the response body JsonNode json = jsonParser.readTree( new InputStreamReader(get.getResponseBodyAsStream(), get.getResponseCharSet()) );
HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager()); GetMethod httpget = new GetMethod("http://www.myhost.com/"); try { httpclient.executeMethod(httpget); Reader reader = new InputStreamReader( httpget.getResponseBodyAsStream(), httpget.getResponseCharSet()); // consume the response entity } finally { httpget.releaseConnection(); }
HttpClient httpclient = new HttpClient(); GetMethod httpget = new GetMethod("http://www.myhost.com/"); try { httpclient.executeMethod(httpget); Reader reader = new InputStreamReader(httpget.getResponseBodyAsStream(), httpget.getResponseCharSet()); // consume the response entity } finally { httpget.releaseConnection(); }
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; }
public static OGObject fetchAndParse(HttpClient httpClient,String uri) throws IOException{ GetMethod get = null; try{ get = new GetMethod(uri); int status = httpClient.executeMethod(get); if (status==HttpStatus.SC_OK){ InputStreamReader reader = new InputStreamReader(get.getResponseBodyAsStream(),get.getResponseCharSet()); return parse(reader,UNESCAPE_HTML_FIELDS); } else{ return null; } } finally{ if (get!=null){ get.releaseConnection(); } } }
try { httpClient.executeMethod(getMethod); Reader reader = new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet());
log.debug("Building GeoRSS reader out of URL response"); String contentEncoding = getMethod.getResponseCharSet(); if (contentEncoding == null) { contentEncoding = "UTF-8";
log.debug("Building GeoRSS reader out of URL response"); String contentEncoding = getMethod.getResponseCharSet(); if (contentEncoding == null) { contentEncoding = "UTF-8";
return new AuthenticationServiceCapabilities(getMethod.getResponseBodyAsStream(),getMethod.getResponseCharSet());
@Override public GetMethod executeRequest( URL url, Map<String, String> queryParams, Integer backendTimeout) throws HttpException, IOException { GetMethod response = EasyMock.createMock(GetMethod.class); expect(response.getStatusCode()).andReturn(200); expect(response.getResponseBodyAsStream()) .andReturn(new ByteArrayInputStream(responseBody)); expect(response.getResponseCharSet()).andReturn("UTF-8"); expect(response.getResponseHeader("Content-Type")).andReturn(null); response.releaseConnection(); expectLastCall(); replay(response); return response; } });
String contentType = (contentTypeHeader != null) ? contentTypeHeader.getValue() : ""; String responseCharset = getMethod.getResponseCharSet(); if (responseCharset==null || responseCharset.length()==0) responseCharset="UTF-8";
response.setCharacterEncoding(getMethod.getResponseCharSet()); response.setContentType(getMethod.getResponseHeader("Content-Type").getValue());
@Override public GetMethod executeRequest( URL url, Map<String, String> queryParams, Integer backendTimeout, WMSLayer.HttpRequestMode httpRequestMode) throws HttpException, IOException { GetMethod response = EasyMock.createMock(GetMethod.class); expect(response.getStatusCode()).andReturn(200); expect(response.getResponseBodyAsStream()) .andReturn(new ByteArrayInputStream(responseBody)); expect(response.getResponseCharSet()).andReturn("UTF-8"); expect(response.getResponseHeader("Content-Type")) .andReturn(new Header("Content-Type", "image/png")); response.releaseConnection(); expectLastCall(); replay(response); return response; } });
curCharSet=charSet; if(curCharSet==null) curCharSet = method.getResponseCharSet(); if(curCharSet!=null && curCharSet.equalsIgnoreCase("ISO-8859-1") ) curCharSet=null;
method.getResponseCharSet())); String json_str=""; String str;