java - Connection successfully downloads on one screen, gets error on second screen with virtually the same code -
i'm getting unusual event when trying download "success" message same php file 2 different screens both have same connection code. each page has button connect , homecoming success plus php file's information. thought on why happening? connections both successful, homecoming 200 in both cases.
appinfo returns "success" purchase returns this:
11-14 11:23:14.209: d/jwp(2395): <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="refresh" content="0;url=http://finder.cox.net/main?interceptsource=0&clientlocation=us&participantid=96e687opkbv4scrood8k84drs6gw5duf&failuremode=1&searchquery=&faileduri=http%3a%2f%2fsinfo.txt%2ftest.php&addintype=4&version=2.1.8-1.90base&referer=&implementation=0&method=get"/> <script type="text/javascript"> url="http://finder.cox.net/main?interceptsource=0&clientlocation=us&participantid=96e687opkbv4scrood8k84drs6gw5duf&failuremode=1&searchquery=&faileduri=http%3a%2f%2fsinfo.txt%2ftest.php&addintype=4&version=2.1.8-1.90base&referer=&implementation=0&method=get";if(top.location!=location){var w=window,d=document,e=d.documentelement,b=d.body,x=w.innerwidth||e.clientwidth||b.clientwidth,y=w.innerheight||e.clientheight||b.clientheight;url+="&w="+x+"&h="+y;}window.location.replace(url); </script> </head> <body></body> </html>
here's code both pages:
public class appinfo extends activity { textview textview; public static final string debugtag = "jwp"; public static final string databasepassword = "pinfo.txt"; public static final string serverip = "sinfo.txt"; public static final string databaseuser = "ninfo.txt"; public static final string database = "dinfo.txt"; public static final string filesaved = "filesaved"; public edittext txtdata; public edittext database; public edittext databaseuser; public edittext databasepassword; public edittext serverip; public textview resultview; public string result = ""; public inputstream isr = null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_app_info); serverip = (edittext) findviewbyid(r.id.server); sharedpreferences prefs = getpreferences(mode_private); boolean filesaved = prefs.getboolean(filesaved, true); if (filesaved) { loadsavedfile(); loadsavedfile2(); loadsavedfile3(); loadsavedfile4(); } addsavebuttonlistener(); addtestbuttonlistener(); } // / load saved info phone private void loadsavedfile() { } private void loadsavedfile2() { } private void loadsavedfile3() { } private void loadsavedfile4() { } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.app_info, menu); homecoming true; } private void addsavebuttonlistener() { } private void addtestbuttonlistener() { button test = (button) findviewbyid(r.id.testcon); test.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { new downloaddata().execute("http://" + serverip.gettext().tostring() + "/test.php"); log.d(mainactivity.debugtag, "http://" + serverip.gettext().tostring() + "/test.php"); } }); } private class downloaddata extends asynctask<string, void, string> { string myxmldata; protected string doinbackground(string... urls) { seek { myxmldata = downloadxml(urls[0]); } grab (ioexception e) { log.e("can not connect database", e.tostring()); homecoming "unable downlad xml file."; } homecoming ""; } protected void onpostexecute(string result) { log.d("jwp", myxmldata); toast.maketext(appinfo.this, getstring(r.string.toast_success), toast.length_long).show(); } private string downloadxml(string theurl) throws ioexception { int buffer_size = 2000; inputstream = null; string xmlcontents = ""; seek { url url = new url(theurl); httpurlconnection conn = (httpurlconnection) url .openconnection(); conn.setreadtimeout(10000); conn.setconnecttimeout(15000); conn.setrequestmethod("get"); conn.setdoinput(true); int response = conn.getresponsecode(); log.d("jwp", "the response " + response); = conn.getinputstream(); inputstreamreader isr = new inputstreamreader(is); int charread; char[] inputbuffer = new char[buffer_size]; seek { while ((charread = isr.read(inputbuffer)) > 0) { string readstring = string.copyvalueof(inputbuffer, 0, charread); xmlcontents = readstring; inputbuffer = new char[buffer_size]; } homecoming xmlcontents; } grab (ioexception e) { log.e("can not connect database", e.tostring()); e.printstacktrace(); homecoming null; } } { if (is != null) is.close(); } } } }
here's purchase page:
public class purchase extends scan { public static final string filesaved = "filesaved"; public static final string serverip = "sinfo.txt"; public string serverip; public string result = ""; public inputstream isr = null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_buy); sharedpreferences prefs = getpreferences(mode_private); boolean filesaved = prefs.getboolean(filesaved, true); if (filesaved) { loadsavedfile(); loadsavedfile2(); } addsendbuttonlistener(); } private void loadsavedfile() { seek { fileinputstream fis = openfileinput(vinholder); bufferedreader reader = new bufferedreader(new inputstreamreader( new datainputstream(fis))); textview edittext = (textview) findviewbyid(r.id.buyvin); string line; while ((line = reader.readline()) != null) { edittext.append(line); edittext.append(""); } fis.close(); sharedpreferences prefs = getpreferences(mode_private); sharedpreferences.editor editor = prefs.edit(); editor.putboolean(filesaved, true); editor.commit(); } grab (exception e) { log.d(debugtag, "can not read file"); } } private void loadsavedfile2() { seek { fileinputstream fis = openfileinput(serverip); // bufferedreader reader = new bufferedreader(new inputstreamreader( // new datainputstream(fis))); serverip = serverip.tostring(); fis.close(); sharedpreferences prefs = getpreferences(mode_private); sharedpreferences.editor editor = prefs.edit(); editor.putboolean(filesaved, true); editor.commit(); } grab (exception e) { log.d(debugtag, "can not read file"); } } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.buy, menu); homecoming true; } private void addsendbuttonlistener() { button send = (button) findviewbyid(r.id.send); send.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { new downloaddata().execute("http://" + serverip.tostring() + "/test.php"); log.d("jwp", "http://" + serverip.tostring() + "/test.php"); } }); } private class downloaddata extends asynctask<string, void, string> { string myxmldata; protected string doinbackground(string... urls) { seek { myxmldata = downloadxml(urls[0]); } grab (ioexception e) { log.e("can not connect database", e.tostring()); homecoming "unable downlad xml file."; } homecoming ""; } protected void onpostexecute(string result) { log.d("jwp", myxmldata); toast.maketext(buy.this, getstring(r.string.toast_success), toast.length_long).show(); } private string downloadxml(string theurl) throws ioexception { int buffer_size = 2000; inputstream = null; string xmlcontents = ""; seek { url url = new url(theurl); httpurlconnection conn = (httpurlconnection) url .openconnection(); conn.setreadtimeout(10000); conn.setconnecttimeout(15000); conn.setrequestmethod("get"); conn.setdoinput(true); int response = conn.getresponsecode(); log.d("jwp", "the response " + response); = conn.getinputstream(); inputstreamreader isr = new inputstreamreader(is); int charread; char[] inputbuffer = new char[buffer_size]; seek { while ((charread = isr.read(inputbuffer)) > 0) { string readstring = string.copyvalueof(inputbuffer, 0, charread); xmlcontents = readstring; inputbuffer = new char[buffer_size]; } homecoming xmlcontents; } grab (ioexception e) { log.e("can not connect database", e.tostring()); e.printstacktrace(); homecoming null; } } { if (is != null) is.close(); }}}}
look @ error message, in particular faileduri:
faileduri=http%3a%2f%2fsinfo.txt%2ftest.php
you're trying nail http://sinfo.txt/test.php
. since hostname doesn't exist, you're getting isp's dns redirection page.
fix code, go yell @ isp , dns redirection disabled.
java php android
No comments:
Post a Comment