forked from ztgreenleaves/JavaWeatherApplication
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpUtil.java
More file actions
35 lines (29 loc) · 1.16 KB
/
Copy pathHttpUtil.java
File metadata and controls
35 lines (29 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package Utils;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class HttpUtil {
public static String getXML(String url) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
CloseableHttpResponse response1 = httpclient.execute(httpGet);
HttpEntity entity1 = response1.getEntity();
entity1.getContent();
String response = EntityUtils.toString(entity1, "UTF-8");
EntityUtils.consume(entity1);
return response;
}
public static InputStream getXMLStream(String url) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
CloseableHttpResponse response1 = httpclient.execute(httpGet);
HttpEntity entity1 = response1.getEntity();
// String response = EntityUtils.toString(entity1, "UTF-8");
// EntityUtils.consume(entity1);
return entity1.getContent();
}
}