문자열의 웹 사이트 응답을 반환하는 자바 메소드가 있습니다. 이제이 요청의 진행 상황을 추적 할 수있는 가능성을 추가하고 싶습니다. 내가 (contenLength/readBytes) * 100 통해 계산할 수 있습니다. 하지만이 정보를 올바르게 검색하고 변경 될 때마다 진행 상황을 업데이트하는 방법을 모르겠습니다. 현재 방법은 다음과 같습니다.Java에서 HTTPRequest 진행하기
public String executePost(URL url) {
StringBuffer sb = new StringBuffer();
int readBytes = 0;
int contentLength = 0;
int progress = 0;
try {
String newString = url.toString().replace(" ", "%20");
URL newURL = new URL(newString);
URLConnection conn = newURL.openConnection();
conn.setDoOutput(true);
contentLength = conn.contentLength();
BufferedReader rd = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
readBytes += line.getBytes("ISO-8859-2").length + 2;
progress = (readBytes/contentLength)*100;
System.out.println(progress);
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
를 통해 대기 커서를 표시하여 그것을 해결하고 -은'println' 작품을 그 목적을 위해, 아니? 콜백 메소드를'executePost()'에 전달할 수 있습니까? 답변에 대한 –