Hi Everyone,
now I'm using HttpClient to upload file, but still unsuccessful! The error code is 415, unsupported media, but the file I want to update is just a JPG! Before that, I can use http://admin:[email protected]:8080/content/nemoclient?sling:authRequestLogin=1 to upload files! So can someone help me to fix this error? Thanks very much! HttpClient httpClient=new HttpClient(); httpClient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin"); httpClient.getState().setCredentials(new AuthScope("141.83.80.149", 8080, AuthScope.ANY_REALM), defaultcreds); PutMethod put = new PutMethod(transferURL); InputStream stream; stream = new FileInputStream(localFile); RequestEntity entity = new InputStreamRequestEntity(stream); put.setRequestEntity(entity); put.setDoAuthentication(true); HttpClientParams params=new HttpClientParams(); params.setIntParameter("sling:authRequestLogin", 1); httpClient.setParams(params); httpClient.executeMethod(put); On Fri, Nov 19, 2010 at 10:19 PM, Bertrand Delacretaz < [email protected]> wrote: > Hi, > > On Fri, Nov 19, 2010 at 3:12 PM, Zhongmiao Li <[email protected]> > wrote: > > Thanks very much! And can you tell me the specfic code of > > registering with the HttpClient object... > > The setUp method of our HttpTestBase class [1] should help. > > -Bertrand > > [1] > http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java > -- Best regards Li Zhongmiao Digital Media, College of Computer Science, Zhejiang University
