目前项目在开发环境使用的是tomcat 预发布环境和生产环境使用的是resin
在调用预发布中post接口中发现一直报 POST requires content-length 很是郁闷
通过查看resin源码发现一个很有意思的代码
com.caucho.server.http.HttpRequest
public boolean initStream(ReadStream readStream, ReadStream rawRead)
throws IOException
{
rawRead.setSibling(null);
if (getConnection().isDuplex()) {
this._rawInputStream.init(rawRead);
readStream.init(this._rawInputStream, null);
return true;
}
long contentLength = getLongContentLength();
if ((contentLength < 0L) && (257 <= getVersion()) && (getHeader("Transfer-Encoding") != null))
{
this._chunkedInputStream.init(rawRead);
readStream.init(this._chunkedInputStream, null);
return true;
}
if (contentLength >= 0L) {
this._contentLengthStream.init(rawRead, contentLength);
readStream.init(this._contentLengthStream, null);
return true;
}
if (getMethod().equals("POST")) {
this._contentLengthStream.init(rawRead, 0L);
readStream.init(this._contentLengthStream, null);
throw new BadRequestException("POST requires content-length");
}
this._contentLengthStream.init(rawRead, 0L);
readStream.init(this._contentLengthStream, null);
return false;
}
从这个方法中可以看出只要前面的3个条件没有进去直接到第4个条件时只要是post请求直接抛异常
处理方式直接在发送http请求时在header中加上
Transfer-Encoding = utf-8
以上只是自己碰到这个问题的一个处理方式。