我正在尝试将没有正文的请求发送到一些REST服务url。
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Length", "0"); //tried with/without
con.setDoOutput(true); //tried with/without
con.connect();
回应是:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">
</HEAD>
<BODY>
<h2>Length Required</h2>
<hr>
<p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY>
</HTML>
(将帖子发送到与POSTMAN worked相同的链接)
https://stackoverflow.com/questions/42053107
复制相似问题