我正在尝试为 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>";
HTTPURL连接
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();