Sunday, 15 August 2010

xmlhttprequest - Page content to a string - Android -



xmlhttprequest - Page content to a string - Android -

i have next php page returns 1 or 0: http://klh-dev.com/lehava/lehava/system/isloggedin.php i'm trying create public string returnes page content (which 0 or 1). tried several times few different things got errors.

i tried this:

public string isloggedin() { string url_text = "http://klh-dev.com/lehava/lehava/system/isloggedin.php"; string response_str = null; seek { httpclient client = new defaulthttpclient(); httpget request = new httpget(url_text.tostring()); responsehandler<string> responsehandler = new basicresponsehandler(); response_str = client.execute(request, responsehandler); } grab (exception e) { system.out.println("there error"); } homecoming response_str; }

i have tried few other things same thing happend.

errors:

11-01 08:27:07.677: i/system.out(24314): android.os.networkonmainthreadexception 11-01 08:27:07.677: w/system.err(24314): android.os.networkonmainthreadexception 11-01 08:27:07.677: w/system.err(24314): @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1145) 11-01 08:27:07.688: w/system.err(24314): @ java.net.inetaddress.lookuphostbyname(inetaddress.java:385) 11-01 08:27:07.688: w/system.err(24314): @ java.net.inetaddress.getallbynameimpl(inetaddress.java:236) 11-01 08:27:07.688: w/system.err(24314): @ java.net.inetaddress.getallbyname(inetaddress.java:214) 11-01 08:27:07.688: w/system.err(24314): @ org.apache.http.impl.conn.defaultclientconnectionoperator.openconnection(defaultclientconnectionoperator.java:137) 11-01 08:27:07.688: w/system.err(24314): @ org.apache.http.impl.conn.abstractpoolentry.open(abstractpoolentry.java:164) 11-01 08:27:07.688: w/system.err(24314): @ org.apache.http.impl.conn.abstractpooledconnadapter.open(abstractpooledconnadapter.java:119) 11-01 08:27:07.688: w/system.err(24314): @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:360) 11-01 08:27:07.688: w/system.err(24314): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:555) 11-01 08:27:07.688: w/system.err(24314): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:653) 11-01 08:27:07.688: w/system.err(24314): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:627) 11-01 08:27:07.688: w/system.err(24314): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:616) 11-01 08:27:07.688: w/system.err(24314): @ com.klh.lehava.mainactivity.isloggedin(mainactivity.java:378) 11-01 08:27:07.688: w/system.err(24314): @ com.klh.lehava.mainactivity.selectitem(mainactivity.java:221) 11-01 08:27:07.688: w/system.err(24314): @ com.klh.lehava.mainactivity.access$0(mainactivity.java:170) 11-01 08:27:07.688: w/system.err(24314): @ com.klh.lehava.mainactivity$draweritemclicklistener.onitemclick(mainactivity.java:166) 11-01 08:27:07.688: w/system.err(24314): @ android.widget.adapterview.performitemclick(adapterview.java:298) 11-01 08:27:07.688: w/system.err(24314): @ android.widget.abslistview.performitemclick(abslistview.java:1114) 11-01 08:27:07.688: w/system.err(24314): @ android.widget.abslistview$performclick.run(abslistview.java:2912) 11-01 08:27:07.688: w/system.err(24314): @ android.widget.abslistview$3.run(abslistview.java:3646) 11-01 08:27:07.688: w/system.err(24314): @ android.os.handler.handlecallback(handler.java:733) 11-01 08:27:07.688: w/system.err(24314): @ android.os.handler.dispatchmessage(handler.java:95) 11-01 08:27:07.688: w/system.err(24314): @ android.os.looper.loop(looper.java:136) 11-01 08:27:07.688: w/system.err(24314): @ android.app.activitythread.main(activitythread.java:5144) 11-01 08:27:07.688: w/system.err(24314): @ java.lang.reflect.method.invokenative(native method) 11-01 08:27:07.688: w/system.err(24314): @ java.lang.reflect.method.invoke(method.java:515) 11-01 08:27:07.688: w/system.err(24314): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:795) 11-01 08:27:07.688: w/system.err(24314): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:611) 11-01 08:27:07.698: w/system.err(24314): @ dalvik.system.nativestart.main(native method)

thank you, morha13

android.os.networkonmainthreadexception

the exception thrown when application attempts perform networking operation on main thread.

this thrown applications targeting honeycomb sdk or higher. applications targeting before sdk versions allowed networking on main event loop threads, it's heavily discouraged. see document designing responsiveness. need add together thread

new thread(new runnable() {

@override public void run() { httpclient client=new defaulthttpclient(); httpget get=new httpget("http://klh-dev.com/lehava/lehava/system/isloggedin.php"); responsehandler<string> responsehandler = new basicresponsehandler(); string response_str = null; seek { response_str=client.execute(get,responsehandler); system.out.println(response_str); } grab (clientprotocolexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } } }).start();

android xmlhttprequest androidhttpclient

No comments:

Post a Comment