I have a client to upload a file to the server through the https post. It uses a proxy server and this is my code
public void upload() throws Exception {
DefaultHttpClient client = new DefaultHttpClient();
if (proxy.equals("yes") && proxyAuth.equals("yes")){
client.getCredentialsProvider().setCredentials(
new AuthScope(address, port),
new UsernamePasswordCredentials(proxyUsername, proxyPassword));
}
if (proxy.equals("yes")){
HttpHost proxy = new HttpHost(address, port);
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
}
HttpPost post = new HttpPost(url);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
File dir = new File(inputFilePath);
File[] fileArray = dir.listFiles();
File file = fileArray[0];
FileBody uploadFilePart = new FileBody(file);
entity.addPart("file", uploadFilePart);
entity.addPart("username", new StringBody(username));
entity.addPart("password", new StringBody(password));
post.setEntity(entity);
String response = EntityUtils.toString(client.execute(post).getEntity(), "UTF-8");
client.getConnectionManager().shutdown();
log4j.info(response);
if(!response.substring(0, 3).equalsIgnoreCase("200")){
Exception e = new Exception("An error has occurred server side: ");
throw e;
}
}
Now the problem is that it works fine sometimes, and sometimes I get the following error.
org.apache.http.impl.client.AbstractAuthenticationHandler.selectScheme (AbstractAuthenticationHandler.java:149) - ntlm authentication scheme is not supported "
source
share