You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by David Motes <da...@gmail.com> on 2008/07/18 15:49:47 UTC

Re: PUT & Expect:100-continu

 You are not specifying an entity to upload.

The 100 is handled by HTTPClient, you will not see it.

This code snippet works with a 100 from the server.

        FileInputStream fStream = null;
        try {
        fStream = new FileInputStream( file );
        }
        catch (java.io.FileNotFoundException e )
        {
            System.out.println("File not Found error " + fileName );
            completionCode = "NOTFOUND";
            return false;
        }

        ProgressMonitorInputStream pmis = new
ProgressMonitorInputStream( null, "Uploading File " +
mdoFile.toString(), fStream );
        pmis.getProgressMonitor().setMaximum((int)uploadFileSize);

        InputStreamRequestEntity iRequest = new
InputStreamRequestEntity( pmis, uploadFileSize );


        PutMethod method = null;

        //create a method object
            method = new PutMethod(url);

            method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,
true);

            method.setFollowRedirects(false);
            method.addRequestHeader("Content-Length", xfileSize );
            method.addRequestHeader("Content-Type",
"application/octet-stream" );
            method.setContentChunked( false );
            method.setRequestEntity( iRequest);


        //execute the method

        String responseBody = null;
        try{
            client.executeMethod(method);
            responseBody = method.getResponseBodyAsString();
        } catch (HttpException he) {
            System.err.println("http exception " + he.getMessage() );
            isCorrect = false;
        }
        catch (IOException ioe){
            System.err.println("Unable to connect to '" + url + "'");
            completionCode = "COMMERR";
            isCorrect =  false;
        }

        if ( isCorrect )
        {

               Header[] responseHeaders = method.getResponseHeaders();
            for (int i=0; i<responseHeaders.length; i++){
                    String tempString = responseHeaders[i].getName();

               // Look at response headers
            }
        }




-David

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org