从 HttpUrlConnection 对象获取标头
我想向 servlet 发送请求并从响应中读取标头。所以我试试这个:
URL url = new URL(contextPath + "file_operations");
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("charset", "utf-8");
conn.setUseCaches(false);
conn.setConnectTimeout(1000 * 5);
conn.connect();
conn.getHeaderField("MyHeader")
.....
但收到的标头始终是 。Servlet工作正常(我尝试使用独立的HTTP客户端使用Servlet)null