Webサイトにログインしてデータを読み取りたいのですが、コードが機能しません
これは私がログインしたいウェブサイトからの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は出力しません。問題がどこにあるのかわかりません。