Untitled
unknown
plain_text
2 years ago
1.5 kB
4
Indexable
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpRequestExample {
public static void main(String[] args) {
try {
String url = "https://server.b-place.co.il/send?receiver=972545847227&msgtext=Testing+send+message+through+API&token=31Btm4uiWNlQq3QmmVSO";
// Create a URL object
URL obj = new URL(url);
// Open a connection
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// Set the request method to GET
con.setRequestMethod("GET");
// Get the response code
int responseCode = con.getResponseCode();
System.out.println("Response Code: " + responseCode);
// Read the response
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// Print the response
System.out.println("Response: " + response.toString());
// Close the connection
con.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}Editor is loading...