我正在尝试向服务器发送 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