我的代码只能返回响应状态消息或状态代码,但我需要我的代码以“查看源”格式返回响应,即 XML 格式:
import java.io.IOException;
import java.net.URL;
import java.net.HttpURLConnection;
public class API{
public static void main(String args[]) throws IOException
{
URL url = new URL("http://example.com");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
String statusCode = http.getResponseMessage();
System.out.println(statusCode);
}
}