problem to upload a zip file and a metadat file on a http server with authentication?

  • Antworten:7
  • Bentwortet
Alex
  • Forum-Beiträge: 17

14.03.2012, 10:03:35 via Website

hi all,

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 =)

Antworten
Rafael K.
  • Forum-Beiträge: 2.359

14.03.2012, 10:24:11 via Website

Alex
but somehow it wont work.
With that much information, the best answer would be "you have to do something somewhere differently" :)

Seriously:
At least the error message + LogCat output (e.g. Stacktrace) is needed to make any assumptions on the reason.

Antworten
Alex
  • Forum-Beiträge: 17

14.03.2012, 10:35:28 via Website

ok sorry =) i'm new in posting my problems =)

well when i try to connect without proxxy i get following LogCat.

03-14 09:34:44.695: W/System.err(3445): java.net.UnknownHostException: Unable to resolve host "dev.steinbauerusa.com": No address associated with hostname
03-14 09:34:44.695: W/System.err(3445): at java.net.InetAddress.lookupHostByName(InetAddress.java:426)
03-14 09:34:44.695: W/System.err(3445): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
03-14 09:34:44.695: W/System.err(3445): at java.net.InetAddress.getAllByName(InetAddress.java:220)
03-14 09:34:44.695: W/System.err(3445): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
03-14 09:34:44.695: W/System.err(3445): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
03-14 09:34:44.695: W/System.err(3445): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
03-14 09:34:44.695: W/System.err(3445): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
03-14 09:34:44.695: W/System.err(3445): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
03-14 09:34:44.695: W/System.err(3445): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
03-14 09:34:44.695: W/System.err(3445): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
03-14 09:34:44.695: W/System.err(3445): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
03-14 09:34:44.695: W/System.err(3445): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
03-14 09:34:44.695: W/System.err(3445): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
03-14 09:34:44.695: W/System.err(3445): at com.app.stt.FileListActivity.zip(FileListActivity.java:133)
03-14 09:34:44.695: W/System.err(3445): at com.app.stt.FileListActivity$1.onItemClick(FileListActivity.java:154)
03-14 09:34:44.695: W/System.err(3445): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
03-14 09:34:44.695: W/System.err(3445): at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
03-14 09:34:44.695: W/System.err(3445): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
03-14 09:34:44.695: W/System.err(3445): at android.widget.AbsListView$1.run(AbsListView.java:3168)
03-14 09:34:44.695: W/System.err(3445): at android.os.Handler.handleCallback(Handler.java:605)
03-14 09:34:44.695: W/System.err(3445): at android.os.Handler.dispatchMessage(Handler.java:92)
03-14 09:34:44.695: W/System.err(3445): at android.os.Looper.loop(Looper.java:137)
03-14 09:34:44.695: W/System.err(3445): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-14 09:34:44.695: W/System.err(3445): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 09:34:44.695: W/System.err(3445): at java.lang.reflect.Method.invoke(Method.java:511)
03-14 09:34:44.695: W/System.err(3445): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-14 09:34:44.695: W/System.err(3445): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-14 09:34:44.695: W/System.err(3445): at dalvik.system.NativeStart.main(Native Method)
03-14 09:34:44.695: W/System.err(3445): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
03-14 09:34:44.695: W/System.err(3445): at libcore.io.Posix.getaddrinfo(Native Method)
03-14 09:34:44.695: W/System.err(3445): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
03-14 09:34:44.695: W/System.err(3445): at java.net.InetAddress.lookupHostByName(InetAddress.java:411)
03-14 09:34:44.695: W/System.err(3445): ... 27 more






and with proxxy it is

03-14 09:32:12.703: W/System.err(3311): java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 8888): connect failed: ECONNREFUSED (Connection refused)
03-14 09:32:12.710: W/System.err(3311): at libcore.io.IoBridge.connect(IoBridge.java:114)
03-14 09:32:12.710: W/System.err(3311): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
03-14 09:32:12.710: W/System.err(3311): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
03-14 09:32:12.710: W/System.err(3311): at java.net.Socket.connect(Socket.java:842)
03-14 09:32:12.710: W/System.err(3311): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77)
03-14 09:32:12.710: W/System.err(3311): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
03-14 09:32:12.710: W/System.err(3311): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
03-14 09:32:12.710: W/System.err(3311): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
03-14 09:32:12.710: W/System.err(3311): at libcore.net.http.HttpConnection.connect(HttpConnection.java:99)
03-14 09:32:12.710: W/System.err(3311): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
03-14 09:32:12.710: W/System.err(3311): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
03-14 09:32:12.710: W/System.err(3311): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
03-14 09:32:12.710: W/System.err(3311): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
03-14 09:32:12.710: W/System.err(3311): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
03-14 09:32:12.710: W/System.err(3311): at com.app.stt.FileListActivity.zip(FileListActivity.java:133)
03-14 09:32:12.710: W/System.err(3311): at com.app.stt.FileListActivity$1.onItemClick(FileListActivity.java:154)
03-14 09:32:12.710: W/System.err(3311): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
03-14 09:32:12.710: W/System.err(3311): at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
03-14 09:32:12.710: W/System.err(3311): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
03-14 09:32:12.710: W/System.err(3311): at android.widget.AbsListView$1.run(AbsListView.java:3168)
03-14 09:32:12.710: W/System.err(3311): at android.os.Handler.handleCallback(Handler.java:605)
03-14 09:32:12.718: W/System.err(3311): at android.os.Handler.dispatchMessage(Handler.java:92)
03-14 09:32:12.718: W/System.err(3311): at android.os.Looper.loop(Looper.java:137)
03-14 09:32:12.718: W/System.err(3311): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-14 09:32:12.718: W/System.err(3311): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 09:32:12.718: W/System.err(3311): at java.lang.reflect.Method.invoke(Method.java:511)
03-14 09:32:12.718: W/System.err(3311): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-14 09:32:12.718: W/System.err(3311): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-14 09:32:12.718: W/System.err(3311): at dalvik.system.NativeStart.main(Native Method)
03-14 09:32:12.718: W/System.err(3311): Caused by: libcore.io.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
03-14 09:32:12.718: W/System.err(3311): at libcore.io.Posix.connect(Native Method)
03-14 09:32:12.718: W/System.err(3311): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:75)
03-14 09:32:12.718: W/System.err(3311): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
03-14 09:32:12.718: W/System.err(3311): at libcore.io.IoBridge.connect(IoBridge.java:112)
03-14 09:32:12.718: W/System.err(3311): ... 28 more




there are no other errors. The program works on but didn't connect

hopefully now someone can help me =)

Antworten
reiti.net
  • Forum-Beiträge: 339

14.03.2012, 11:01:38 via Website

hostname cannot be resolved ... I've tried manually and DNS entries just work fine, I'll get this IP 173.230.128.43

So it looks like you have not entered a valid DNS Adress on that specific device? does your browser work normally?

— geändert am 14.03.2012, 11:03:10

Antworten
Alex
  • Forum-Beiträge: 17

14.03.2012, 13:12:38 via Website

ok i made it to get connected to the server.

but how can i upload 2 files whitch are existing on my phone?

Antworten
Rafael K.
  • Forum-Beiträge: 2.359

14.03.2012, 13:19:16 via Website

Take a look at this: http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/

Stock Android 2.3 versions have an older version of the HttpClient library, which does not support file-upload correctly.
I had to add the newest version of the HttpClient to my project for image upload to work.

Works quite nicely, but can cause some problems with Proguard when compiling against the 3.2 sources (you have to do that in order to integrate Admob).
That caused me some serious headache until I managed to resolve this.

Antworten
Alex
  • Forum-Beiträge: 17

14.03.2012, 13:25:14 via Website

thx a lot i'll try =)

Antworten
Alex
  • Forum-Beiträge: 17

14.03.2012, 15:59:02 via Website

ok it is working =)

big thanks

Antworten