hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yannick PIERSON" <piers...@gmail.com>
Subject Re: store file
Date Tue, 22 Apr 2008 14:53:51 GMT
Hi,
Ok thanks a lot for previous message.

I get an error when I'm executing my code : connection is aborted. I've
searched in many documents but I've found nothing. And many topics are not
resolved.
My aim is to put a file on a IIS remote server.

My code :
HttpClient client = new HttpClient();
Credentials credentials = new NTCredentials("user", "pwd", "homecomputer ",
"WORKGROUP");
HttpState state = client.getState();
state.setCredentials(null, null, credentials);

/* List authPrefs = new ArrayList(1); // I think I don't need that if I use
NTCredentials
   authPrefs.add(AuthPolicy.NTLM);
   client.getParams().setParameter(AuthPolicy.NTLM, authPrefs);
*/

client.getParams().setAuthenticationPreemptive(true);

PutMethod put = new PutMethod("http://computer_name/webdav_acces");
put.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new
DefaultHttpMethodRetryHandler(3, false));
// put.setDoAuthentication(true);

File file = new File("c:\\temp\\pdf_file.pdf");
put.setRequestEntity(new FileRequestEntity(file,
"application/octet-stream")), // I tried too with "text/plain;
charset=UTF-8"

client.executeMethod(put);

Trace of the exception :
java.net.SocketException: Software caused connection abort: socket write
error
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at
java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
        at
org.apache.commons.httpclient.WireLogOutputStream.write(WireLogOutputStream.java:68)
        at
org.apache.commons.httpclient.methods.FileRequestEntity.writeRequest(FileRequestEntity.java:76)
        at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
        at
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
        at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
        at javaapplication1.HttpClt.myPost(HttpClt.java:111)
        at javaapplication1.Main.main(Main.java:42)

Thanks,
Regards.

Yannick

2008/4/22, Thierry Boileau <thboileau@gmail.com>:
>
> Hello,
>
> PUT means that you send the new representation of a resource (identified
> by its URI). If this resource does not exists, you create it with the
> provided representation. If it exists you replace its current
> representation.
> POST does not have such a precise definition, and then can be used to
> store file also.
>
> best regards,
> Thierry Boileau
>
>  Hi,
> > To store a file must I execute post or put method (if I understand well,
> > both work, but put method is better) ?
> >
> > Please help
> > Thanks,
> > Regards.
> >
> > Yannick
> >
> > 2008/4/22, Yannick PIERSON <piersony@gmail.com>:
> >
> >
> > > Hi,
> > > I don't understand why it doesn't work. I try many examples (for
> > > example
> > > in a previous message with put method).
> > >
> > > HttpClient client = new HttpClient();
> > > Credentials credentials = new NTCredentials("user", "pwd",
> > > "homecomputer
> > > ", "WORKGROUP");
> > > HttpState state = client.getState();
> > > state.setCredentials(null, null, credentials);
> > >
> > > PostMethod httppost = new PostMethod("
> > > http://computer_name/webdav_acces");
> > > // Is it the good path ?????????????????????????????
> > >
> > > File file = new File("c:\\temp\\my_pdf.pdf");
> > > httppost.setRequestEntity(new InputStreamRequestEntity(new
> > > FileInputStream(file), file.length()));
> > > // httppost.setContentChunked(true);
> > >
> > > client.executeMethod(httppost);
> > >
> > > With this code I get this error :
> > > org.apache.commons.httpclient.ProtocolException: Unbuffered entity
> > > enclosing request can not be repeated.
> > >        at
> > >
> > > org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:487)
> > >        at
> > >
> > > org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
> > >        at
> > >
> > > org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
> > >        at
> > >
> > > org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
> > >        at
> > >
> > > org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
> > >        at
> > >
> > > org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> > >        at
> > >
> > > org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> > >        at javaapplication1.HttpClt.myPost(HttpClt.java:94)
> > >        at javaapplication1.Main.main(Main.java:42)
> > >
> > > Thanks in advance,
> > > Regards.
> > >
> > > Yannick
> > >
> > >
> > >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message