我正在尝试为Android创建一个应用程序,它允许用户从特定网站发送短信,并且还允许检查他们在该网站上的帐户中记入的金额。但我面临一个奇怪的问题。同一段代码在不同类型的仿真器上产生不同的输出。也就是说,当使用TARGET ANDROID 2.3.3
在模拟器上进行测试时,它完美地工作并产生了所需的结果,但是当我在模拟器上使用TARGET GOOGLE APIS - API LEVEL 10
运行相同的应用程序时,我总是得到null
输出。此外,我在我的Android 4.0设备上测试了该应用程序,即使在手机上,我总是以null
作为输出。我正在提出问题的截图。任何人都可以使用TEAMVIEWER
连接到我的计算机并帮助我解决错误,我不能在这里透露完整的代码,但是提出它的想法,这里是我使用的导入
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
并且一些代码是这样的:
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(rs);
截图:
修改
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
response.append(line);
}
String text = response.toString();
int start = text.indexOf("<p>Rs</p>");
int end = text.indexOf("<div class=\"paisa_bg\">");
String rs = text.substring(start, end);
String pattern = "<h1>(\\d+)</h1>";
HttpURLConnection类
String data = URLEncoder.encode("PARAM1", "UTF-8") + "=" + URLEncoder.encode("VALUE1", "UTF-8");
data = data + "&" + URLEncoder.encode("PARAM2", "UTF-8") + "=" + URLEncoder.encode(VALUE2, "UTF-8");
data = data + "&" + URLEncoder.encode("PARAM3", "UTF-8") + "=" + URLEncoder.encode(VALUE3, "UTF-8");
data = data + "&" + URLEncoder.encode("PARAM4", "UTF-8") + "=" + URLEncoder.encode("VALUE4", "UTF-8");
data = data + "&" + URLEncoder.encode("PARAM5", "UTF-8") + "=" + URLEncoder.encode("VALUE5", "UTF-8");
URL url = new URL("http://www.somewebsite.com/somepage.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.29 (KHTML, like Gecko) Chrome/12.0.733.0 Safari/534.29");
conn.setRequestProperty("Cookie", cookie);
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();