java - Microsoft ISA Server Authentication in Android -
i have application in android, in reading files remote server, code reading file given below;
uri uri = null; try { uri = new uri("http://192.168.1.116/server1/users.xml"); } catch (urisyntaxexception e) { e.printstacktrace(); } httpget httpget = new httpget(uri); httpget.setheader("content-type", "application/json; charset=utf-8"); httpget.setheader("host", "192.168.1.116"); httpresponse response = null; try { response = httpclient.execute(httpget); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } httpentity responseentity = response.getentity(); string result = null; try { result = entityutils.tostring(responseentity); log.d("server1", result); } catch (parseexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); }
now remote files behind proxy (microsoft isa server) required authentication access files. please guide me how can pass authentication parameters android access files.
i have tried following codes useless,
url uri = null; try { uri = new uri("http:// 192.168.1.116/cookieauth.dll?logon"); } catch (urisyntaxexception e) { e.printstacktrace(); } defaulthttpclient httpclient = new defaulthttpclient(); httpclient.getcredentialsprovider() .setcredentials( authscope.any, new ntcredentials(username, password, deviceip, domainname)); httppost httppost = new httppost(uri); httppost.setheader("content-type", "application/x-www-form-urlencoded"); list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("curl", "z2fserver1/users.xmlz2f")); params.add(new basicnamevaluepair("formdir", "3")); params.add(new basicnamevaluepair("username", "test")); params.add(new basicnamevaluepair("password", "test")); urlencodedformentity ent = null; try { ent = new urlencodedformentity(params, http.utf_8); } catch (unsupportedencodingexception e1) { // todo auto-generated catch block e1.printstacktrace(); } httppost.setentity(ent); try { response = httpclient.execute(httppost); log.i("test", response.getstatusline().tostring()); httpentity entity = response.getentity(); if (entity != null) { inputstream instream = entity.getcontent(); result = convertstreamtostring(instream); log.d("isa server", result); instream.close(); } } catch (exception e) { e.printstacktrace(); }
but it’s giving http1.1
500 internal server error. have tried following link same error https://stackoverflow.com/a/10937857/67381
in case use
public static defaulthttpclient getclient(string username, string password, integer timeout) { httpparams httpparams = new basichttpparams(); httpconnectionparams.setconnectiontimeout(httpparams, timeout); httpconnectionparams.setsotimeout(httpparams, timeout); defaulthttpclient rethttpclient = new defaulthttpclient(httpparams); if (username != null) { rethttpclient.getcredentialsprovider().setcredentials( new authscope(authscope.any_host, authscope.any_port), new usernamepasswordcredentials(username, password)); } return rethttpclient; }
try, may works.
p.s.
it's not isa, ms c# webservice application, maybe...
Comments
Post a Comment