다음과 같은 방법으로 웹 페이지의 내용을 읽고 싶지만 그 중 60-70 % 만 얻습니다.웹 페이지의 내용 (버퍼)이 불완전합니다.
두 가지 방법으로 웹 페이지를 읽었습니다. 둘 다 동일한 결과를 보았습니다. 나는 또한 다른 URL을 시도했다. 오류나 시간 초과가 없습니다.
내가 뭘 잘못하고 있니?
URL url = new URL(uri.toString());
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try
{
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null)
{
sb.append(line + "\n");
}
br.close();
this.content = sb.toString();
}
finally
{
urlConnection.disconnect();
}
나는 C# 및 윈폼으로 시도했습니다
HttpGet get = new HttpGet(uri);
HttpClient defaultHttp = new DefaultHttpClient(httpParameters);
HttpResponse response = defaultHttp.execute(get);
StatusLine status = response.getStatusLine();
if(status.getStatusCode() == HttpStatus.SC_OK)
{
HttpEntity entity = response.getEntity();
InputStream stream = entity.getContent();
String encoding = "utf-8";
//long length = entity.getContentLength();
//if(entity.getContentEncoding() != null)
//{
// encoding = entity.getContentEncoding().getValue();
//}
//if(length > 0)
//{
byte[] buffer = new byte[1024];
long read = 0;
do
{
read = stream.read(buffer);
if(read > 0)
{
this.content += new String(buffer, encoding);
}
}while(read > 0);
//}
}
@edit. 해당 웹 페이지의 전체 HTML 소스를 읽었습니다. java-android를 사용하면 작동하지 않습니다.
첫눈에 아무 것도 보이지 않습니다. URL을 게시 할 수 있습니까? –
나는 많은 URL을 시도했지만 매번 같은 결과를 보았습니다. webseite의 출처가 아주 작지 않은 경우 완전한 소스를 얻지 못합니다. – Gepro
좋아요, 그래서 당신을 위해 작동하지 않는 URL을 게시 할 수 있습니까? –