httpclient 패키지를 가져오고 .addHeader 및 .execute를 사용하려고했지만 항상 오류가 발생합니다. '' '심볼을 실행할 수 없습니다' '및'addHeader '' 심볼을 해결할 수 없습니다. 필요한 패키지를 가져 왔지만 .왜 '심볼을 처리 할 수 없습니다'가 실행됩니까?
public class MyActivity extends Activity {
public TextView quellcode;
public TextView geschichte;
private String string1 = "gahwareawbad password gagaw";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
quellcode = (TextView) findViewById(com.example.MainActivity.R.id.TextView01);
geschichte = (TextView) findViewById(com.example.MainActivity.R.id.geschichte);
readWebpage(quellcode);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
//AUTOMATIC LOGIN
//END OF LOGIN
//READ WEBPAGE
@Override
protected String doInBackground(String... urls) {
String response = "";
downloadPage("http://www.besselgymnasium.de/fileadmin/Vertretung/Vertretungsplan_Schueler/subst_001.htm");
for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return response;
}
//END OF READING
private void downloadPage (String url){
try{
URL obj = new URL(url);
// Send post request
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes("username"+"password");
wr.flush();
wr.close();
InputStream is = con.getInputStream();
InputStreamReader isr = new InputStreamReader(is,"ISO-8859-1");
BufferedReader br = new BufferedReader(isr);
for (String line = br.readLine(); line != null ; line = br.readLine()) {
// the variable line contains the line of text. You can insert it in your database of file
}
con.disconnect();
} catch (Exception e){
// TODO error handling
}
}
@Override
protected void onPostExecute(String result) {
quellcode.setText(result);
//CHECK IF CLASS IS CANCELED
if(quellcode.getText().toString().contains("eigenverant. Arb.") && quellcode.getText().toString().contains("Pön")){
geschichte.setText("OUTPUT: SUCCESS!");
}else{
geschichte.setText("OUTPUT: FAIL!");
}
//END OF CHECK
}
}
public void readWebpage(View view) {
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[]{"http://www.besselgymnasium.de/fileadmin/Vertretung/Vertretungsplan_Schueler/subst_001.htm"});
}
은}
나는 위의 내 코드를 편집하고 doInBackground 부분을 포함. 코드로 대체해야합니까? – Fynn
@ user2051194 : 예 코드 변경 대답은 –
과 같습니다. 좋아, doInBackground 부분을 코드로 바 꾸었습니다. 이제 오류가 발생합니다 : java :보고되지 않은 예외 java.io.IOException; 이 라인에 이 던져 지거나 잡혀 야합니다. httpclient.execute (request); – Fynn