This is the way that i used for autnenticating a user in a Domino Server, hope will help...
String namesUrl = "http://..." HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(namesUrl); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); //nameValuePairs.add(new BasicNameValuePair("RedirectTo", redirect)); nameValuePairs.add(new BasicNameValuePair("Username", "Username")); nameValuePairs.add(new BasicNameValuePair("Password", "Password")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); Before using this authentication i've tried many different one, without found one that worked, for me... Bye On 26 Nov, 01:54, Seb <[email protected]> wrote: > As the topic indicates I'm trying to perform a http post request to a page > secured with basic http authentication. > > It works from the command line with curl as following: > curlhttp://snot%40snot.dk:supersnot_at_teletracker.herokuapp.com/devices > -d "device[name]=snot" -d "device[device_id]=1234" > > But with the java code below I get redirected to a login form. Any ideas > what I'm doing wrong? > Note that the username and password I have supplied is working so, if > anyone cares, please try it out. You just have to replace _at_ with @ > > private void sendDeviceIdToServer(String deviceId) { > DefaultHttpClient client = new DefaultHttpClient(); > client.getCredentialsProvider().setCredentials( > new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), > new UsernamePasswordCredentials("snot_at_snot.dk", "supersnot")); > //new UsernamePasswordCredentials("snot%40snot%2Edk", "supersnot")); > HttpPost post = new > HttpPost("http://teletracker.herokuapp.com/devices"); > try { > List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); > nameValuePairs.add(new BasicNameValuePair("device[name]", "from > android")); > nameValuePairs.add(new BasicNameValuePair("device[device_id]", > deviceId)); > > post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); > > ResponseHandler<String> handler = new BasicResponseHandler(); > String response = client.execute(post, handler); > Log.d("HttpResponse", response); > } catch (IOException e) { > e.printStackTrace(); > } > } Se hai ricevuto questa comunicazione per errore, ti preghiamo di non inoltrarla a nessun'altra persona in quanto potrebbe contenere informazioni riservate o privilegiate. Cancellane tutte le copie e informa il mittente che il messaggio è stato inviato per errore ad un'altra persona. Grazie. -------------------------------------------------------------------- This email may be confidential or privileged. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it went to the wrong person. Thanks. I termini che precedono rappresentano un potenziale accordo commerciale e costituiscono esclusivamente una base per ulteriori negoziazioni, di conseguenza non danno origine ad obbligazioni legalmente vincolanti né potranno essere interpretati come tali. Nessuna obbligazione legalmente vincolante potrà sorgere o essere ritenuta implicitamente sorta fino a quando tutte le parti coinvolte non abbiano concluso e sottoscritto un accordo definitivo. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

