0
我試圖從兩個不同屏幕上的相同php文件下載「成功」消息時發生奇怪事件,這兩個屏幕都具有相同的連接代碼。每個頁面都有一個連接並返回成功的按鈕以及php文件的信息。任何想法爲什麼發生這種情況?連接都是成功的,在兩種情況下都會返回200。連接在一個屏幕上成功下載,在第二個屏幕上出現幾乎相同的代碼錯誤
AppInfo返回 「成功」 購買返回此:
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>
這裏有兩個頁面的代碼:
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 information from 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);
return 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) {
try {
myXmlData = downloadXML(urls[0]);
} catch (IOException e) {
Log.e("Can not connect Database", e.toString());
return "Unable to downlad XML file.";
}
return "";
}
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 is = null;
String xmlContents = "";
try {
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 is " + response);
is = conn.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
int charRead;
char[] inputBuffer = new char[BUFFER_SIZE];
try {
while ((charRead = isr.read(inputBuffer)) > 0) {
String readString = String.copyValueOf(inputBuffer, 0,
charRead);
xmlContents = readString;
inputBuffer = new char[BUFFER_SIZE];
}
return xmlContents;
} catch (IOException e) {
Log.e("Can not connect Database", e.toString());
e.printStackTrace();
return null;
}
} finally {
if (is != null)
is.close();
}
}
}
}
這裏的購買頁面:
public class Buy 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() {
try {
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();
} catch (Exception e) {
Log.d(DEBUGTAG, "Can not read file");
}
}
private void loadSavedFile2() {
try {
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();
} catch (Exception e) {
Log.d(DEBUGTAG, "Can not read file");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.buy, menu);
return 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) {
try {
myXmlData = downloadXML(urls[0]);
} catch (IOException e) {
Log.e("Can not connect Database", e.toString());
return "Unable to downlad XML file.";
}
return "";
}
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 is = null;
String xmlContents = "";
try {
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 is " + response);
is = conn.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
int charRead;
char[] inputBuffer = new char[BUFFER_SIZE];
try {
while ((charRead = isr.read(inputBuffer)) > 0) {
String readString = String.copyValueOf(inputBuffer, 0,
charRead);
xmlContents = readString;
inputBuffer = new char[BUFFER_SIZE];
}
return xmlContents;
} catch (IOException e) {
Log.e("Can not connect Database", e.toString());
e.printStackTrace();
return null;
}
} finally {
if (is != null)
is.close();
}}}}
啊謝謝!!!不能相信我錯過了 – Glenn 2014-11-14 17:58:41