I'm trying to read custom error message I sent along an HTTP response for a web API project using Java.
Currently, I have this piece of Java code to read Header Response,
import java.net.HttpURLConnection;
import java.net.URL;
public class URLReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL(URL);
HttpURLConnection connection =(HttpURLConnection)oracle.openConnection();
connection.setRequestMethod("GET");
connection.connect();
System.out.println(connection.getHeaderField(0));
}
}
An output of HTTP response header looks like this (Fiddler):
How can I get My Error Message text using Java?
