我正在尝试将PUT(或POST)发送到服务器,但我收到的只是“400次错误请求”。从查看服务器的请求到达apache,但它不会继续到rails。我收到这个错误:
[Mon Jul 11 12:30:52 2011] [error] [client 151.80.29.77] client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23)
如果我发送GET请求,他们都会作为一种享受。这是我的应用程序中相关的代码块。有没有人发现任何错误?
InputStream in = null;
HttpParams params = new BasicHttpParams( );
HttpProtocolParams.setVersion( params, HttpVersion.HTTP_1_1 );
HttpProtocolParams.setContentCharset( params, HTTP.DEFAULT_CONTENT_CHARSET );
HttpProtocolParams.setUseExpectContinue( params, true );
SchemeRegistry schReg = new SchemeRegistry( );
schReg.register( new Scheme( "http", PlainSocketFactory.getSocketFactory( ), 80 ) );
schReg.register( new Scheme( "https", SSLSocketFactory.getSocketFactory( ), 443 ) );
ClientConnectionManager conMgr = new ThreadSafeClientConnManager( params, schReg );
httpClient = new DefaultHttpClient( conMgr, params );
httpClient.setCookieStore( myCookieStore );
HttpClientParams.setRedirecting( httpClient.getParams( ), true );
HttpContext localContext = new BasicHttpContext( );
HttpRequestBase request = null;
request = new HttpPut( url );
request.addHeader( "Host", my_domain );
StringEntity sePut = new StringEntity( data );
( (HttpPut)request ).setEntity( sePut );
HttpResponse response = httpClient.execute( request, localContext );
StatusLine status = response.getStatusLine( ); <------- 400 Bad Request