PostMethod post = new PostMethod("...");
post.setRequestHeader( "Content-type", "text/xml; charset=GB2312" );if( body.length() < Integer.MAX_VALUE )
post.setRequestContentLength( body.length() );
else
post.setRequestContentLength( EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED );post.setRequestBody( body );
try
{
HttpClient client = new HttpClient();
client.executeMethod( post );
//读返回报文,省略....
}
catch( Exception ex )
{
ex.printStackTrace();
return null;
}我的post报文体是程序写的,可能会很长,当长度为8000多个字符的时候,直接给我报400错误:错误内容如下:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><HTML><HEAD><TITLE>400 BadRequest</TITLE></HEAD><BODY><H1>Bad Request</H1>Your browser sent a request that this server could not understand.<P>Request header field is missing colon separator.<P><PRE><?xml version="1.0"?></PRE><P><HR><ADDRESS>ZTE G100 M100 Server at 127.0.0.1 Port 2000</ADDRESS></BODY></HTML>长度较短时确很正常,这是怎么回事哦?急!
post.setRequestHeader( "Content-type", "text/xml; charset=GB2312" );if( body.length() < Integer.MAX_VALUE )
post.setRequestContentLength( body.length() );
else
post.setRequestContentLength( EntityEnclosingMethod.CONTENT_LENGTH_CHUNKED );post.setRequestBody( body );
try
{
HttpClient client = new HttpClient();
client.executeMethod( post );
//读返回报文,省略....
}
catch( Exception ex )
{
ex.printStackTrace();
return null;
}我的post报文体是程序写的,可能会很长,当长度为8000多个字符的时候,直接给我报400错误:错误内容如下:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><HTML><HEAD><TITLE>400 BadRequest</TITLE></HEAD><BODY><H1>Bad Request</H1>Your browser sent a request that this server could not understand.<P>Request header field is missing colon separator.<P><PRE><?xml version="1.0"?></PRE><P><HR><ADDRESS>ZTE G100 M100 Server at 127.0.0.1 Port 2000</ADDRESS></BODY></HTML>长度较短时确很正常,这是怎么回事哦?急!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货