Answer the question
In order to leave comments, you need to log in
How to send an http request with a parameter similar to CURL?
Hello.
It is necessary to extend the capabilities of the HTTP client to java, which will initiate an HTTP request with a parameter
similar to
curl -H "Authorization: newParameter12" "http://server01/status"
String url = "http://server01/status";
URL http_connect = null;
try {
http_connect = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(http_connect.openStream(), "UTF-8"))) {
for (String line; (line = reader.readLine()) != null; ) {
System.out.println(line);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Answer the question
In order to leave comments, you need to log in
This is called a header. Use HttpURLConnection :
HttpURLConnection сonnection = (HttpURLConnection) http_connect.openConnection();
сonnection.setRequestProperty("Authorization", "newParameter12");
http_connect.openStream()
use connection.getInputStream()
. Only in real projects is it still worth using a ready-made solution, and not producing such bicycles.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question