-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGET.java
More file actions
34 lines (27 loc) · 831 Bytes
/
GET.java
File metadata and controls
34 lines (27 loc) · 831 Bytes
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
package com.panoskrt.HTTP;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class GET {
public GET() {
}
public String getRequest(String URL, String agent) {
String getResponse = null;
try {
URL obj = new URL(URL);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", agent);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) { response.append(inputLine); }
in.close();
getResponse = response.toString();
} catch (Exception ex) {
ex.printStackTrace();
}
return getResponse;
}
}