- Forum-Beiträge: 17
14.03.2012, 10:03:35 via Website
14.03.2012 10:03:35 via Website
i'm trying to upload two files to a http server of my company but somehow it wont work. i searched the internet for about 3 days and found a lot of information but it still doesn't do anything.
i tryed a few methodes. Here the examples
1)
URL url=new URL("http://dev.steinbauerusa.com:8888/boxlogs/");
// Authenticator.setDefault(new Authenticator(){
// protected PasswordAuthentication getPasswordAuthentication() {
// return new PasswordAuthentication("username","password".toCharArray());
// }});
// HttpHost proxyHost = new HttpHost("127.0.0.1", 8888, "http");
//
// Proxy proxy = new Proxy(Proxy.Type.HTTP,
// new InetSocketAddress(proxyHost.getHostName(), 8888));
// HttpURLConnection c = (HttpURLConnection)url.openConnection(proxy);
//
//// HttpURLConnection c = (HttpURLConnection) url.openConnection();
// c.setUseCaches(false);
// c.connect();
2)
HttpHost targetHost = new HttpHost("dev.steinbauerusa.com", 8888, "http");
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials("username", "password"));
HttpGet httpget = new HttpGet("http://dev.steinbauerusa.com:8888/boxlogs/");
System.out.println("executing request " + httpget.getRequestLine());
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
//EntityUtils.consume(entity);
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}*/
3)
HttpHost targetHost = new HttpHost("dev.steinbauerusa.com", 8888, "http");
AbstractHttpClient mClient = new DefaultHttpClient();
mClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("username", "password");
mClient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
HttpHost proxyHost = new HttpHost("127.0.0.1", 8888, "http");
mClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost);
HttpPost post = new HttpPost("/api/boxlogs/");
File zip=new File(zipFile);
HttpEntity entity=new FileEntity(zip, zipFile);
// entity.addPart("meta_data", new FileEntity(meta));
// entity.addPart("csv_log", new FileEntity(zip));
post.setEntity(entity);
HttpResponse res = mClient.execute(targetHost, post);
if (res.getStatusLine().getStatusCode() != 201) { // not code 201 CREATED
}
entity.consumeContent();
can someone help me please?
thx =)