我想登录网站并从中读取数据,但我的代码不起作用
这是我要登录的网站的 html 的一部分。要登录,您必须输入卡号并单击“Nastavak”按钮
<span id="rightframe_Label1" class="smalltextcell" style="display:inline-block;width:50px;">Kartica:</span>
<input name="ctl00$rightframe$TextBox1" type="text" value="601983" maxlength="19" id="rightframe_TextBox1" title="Upisati broj kartice">
<input type="submit" name="ctl00$rightframe$ProvjeraSaldoButton" value="Nastavak" id="rightframe_ProvjeraSaldoButton">
这是代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("webpage");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("rightframe_TextBox1", "numberOfCard"));
nameValuePairs.add(new BasicNameValuePair("rightframe_ProvjeraSaldoButton", "Nastavak"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String html = inputStreamToString(response.getEntity().getContent()).toString();
Log.e(Constants.TAG, html);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
private StringBuilder inputStreamToString(InputStream is) throws IOException {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
while ((line = rd.readLine()) != null) {
total.append(line);
}
// Return full string
return total;
}
当我登录时,该代码仅从登录屏幕打印我的 html,但没有从屏幕打印 html。我不知道问题出在哪里