웹 페이지에서 텍스트를 수집하여 문자열에 넣은 다음 장치 화면에 표시하고 싶습니다.문자열로 Android 웹 요청
이 내 WebRequest 클래스 활동 : 내 장치에서 이클립스에 오류,하지만 응용 프로그램이 충돌이없는
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:layout_height="wrap_content"
android:id="@+id/textView1"
android:text=""
android:layout_width="wrap_content"></TextView>
</LinearLayout>
package com.work.webrequest;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class WebRequest extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView txt = (TextView) findViewById(R.id.textView1);
txt.setText(getPage());
}
private String getPage() {
String str = "***";
try
{
HttpClient hc = new DefaultHttpClient();
HttpPost post = new HttpPost("http://zapmenow.co.uk/zapme/?getDetails=true&secret=zjXvwX5frK1po0adXyKJsbbyUe2ZY2PkW9M8r7sb1soIDppIWdTlgt1xmL5VM6g&UDID=401ceca29af68e4569a25e8c16a6987bb8cf1f5a&id=41");
HttpResponse rp = hc.execute(post);
if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
str = EntityUtils.toString(rp.getEntity());
}
}catch(IOException e){
e.printStackTrace();
}
return str;
}
}
main.xml에. 제발, 최대한 빨리 도움이 필요합니다. PS : 인터넷 권한은 문제가되지 않습니다 그래서 나는, 라인 매니페스트
<uses-permission android:name="android.permission.INTERNET" />
을 추가했습니다. 당신은 여기에서 로그 캣 출력을 게시해야
String response = getPage("http://example.com");
:
나중에에 의해 사용할 수 있습니다 : – Knickedi