Jetty POST 请求返回错误代码 411
Jetty POST Request returning error code 411
这是我 运行 POST 请求
的代码
// Instantiate HttpClient
HttpClient httpClient = new HttpClient();
// Configure HttpClient, for example:
httpClient.setFollowRedirects(false);
// Start HttpClient
httpClient.start();
ContentResponse response = httpClient.POST("url")
.agent("Mozilla/5.0")
.method(HttpMethod.POST)
.param("do","login")
.param("url","")
.param("vb_login_md5password", this.password)
.param("vb_login_md5password_utf", this.password)
.param("s", "")
.param("vb_login_username", this.username)
.param("vb_login_password", "")
.send();
for(HttpField h : response.getHeaders())
System.out.println(h.getName() + " = " + h.getValue());
这是输出
Date = Mon, 14 Dec 2015 08:17:08 GMT
Content-Type = text/html
Transfer-Encoding = chunked
Connection = keep-alive
Set-Cookie = __cfduid=dbb11c371945319b1d5943aad06c1977e1450081028; expires=Tue, 13-Dec-16 08:17:08 GMT; path=/; domain=.sythe.org; HttpOnly
Server = cloudflare-nginx
CF-RAY = 2548787ba9dc21b6-EWR
我通过
查看 post 请求的 ContentResponse 文本
response.getContentAsString()
但是由于某种原因,我不断收到 411 错误,告诉我我的 Content-Length 为零或未指定。有没有办法设置 post 的内容长度 header?
谢谢!
编辑:这样做对我的 post 请求没有影响
.header(HttpHeader.CONTENT_LENGTH, "0")
使用 .param("do","login")
指定要添加的 查询参数 。对于 POST 实际包含一个正文,我认为您需要根据请求设置 content()
。也许 FormContentProvider
适合你?
这是我 运行 POST 请求
的代码// Instantiate HttpClient
HttpClient httpClient = new HttpClient();
// Configure HttpClient, for example:
httpClient.setFollowRedirects(false);
// Start HttpClient
httpClient.start();
ContentResponse response = httpClient.POST("url")
.agent("Mozilla/5.0")
.method(HttpMethod.POST)
.param("do","login")
.param("url","")
.param("vb_login_md5password", this.password)
.param("vb_login_md5password_utf", this.password)
.param("s", "")
.param("vb_login_username", this.username)
.param("vb_login_password", "")
.send();
for(HttpField h : response.getHeaders())
System.out.println(h.getName() + " = " + h.getValue());
这是输出
Date = Mon, 14 Dec 2015 08:17:08 GMT
Content-Type = text/html
Transfer-Encoding = chunked
Connection = keep-alive
Set-Cookie = __cfduid=dbb11c371945319b1d5943aad06c1977e1450081028; expires=Tue, 13-Dec-16 08:17:08 GMT; path=/; domain=.sythe.org; HttpOnly
Server = cloudflare-nginx
CF-RAY = 2548787ba9dc21b6-EWR
我通过
查看 post 请求的 ContentResponse 文本response.getContentAsString()
但是由于某种原因,我不断收到 411 错误,告诉我我的 Content-Length 为零或未指定。有没有办法设置 post 的内容长度 header?
谢谢!
编辑:这样做对我的 post 请求没有影响
.header(HttpHeader.CONTENT_LENGTH, "0")
使用 .param("do","login")
指定要添加的 查询参数 。对于 POST 实际包含一个正文,我认为您需要根据请求设置 content()
。也许 FormContentProvider
适合你?