2

I'm trying to send a PUT (or a POST) to a server, but all I receive is a "400 bad request". From a look at the server the request arrives to apache, but it doesn't go on to rails. I get this error:

[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)

If I send GET requests they all go through as a treat. This is the relevant chunck of code in my application. Does anyone spot anything wrong?

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
Stephan
  • 1,858
  • 2
  • 25
  • 46

0 Answers0