Vert. x Http 를 사용 하여 데 이 터 를 발표 할 때의 인 코딩 과 디 코딩
2805 단어 Vert.x
router.get("/" + urlName).handler(event -> event.response().putHeader("content-type", "text/html").end(result));
브 라 우 저 중국어 난 장 판, URLConnection 분석 결 과 를 사용 할 때 기본 디 코딩 을 사용 하면 중국 어 를 인식 합 니 다.
/**
* URL GET
*
* @param url
* URL
* @param param
* , name1=value1&name2=value2 。
* @return URL
*/
public static String sendGet(String url, String param) {
String result = "";
BufferedReader in = null;
try {
String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// URL
URLConnection connection = realUrl.openConnection();
//
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
//
connection.connect();
//
Map> map = connection.getHeaderFields();
//
for (String key : map.keySet()) {
System.out.println(key + "--->" + map.get(key));
}
// BufferedReader URL
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println(" GET !" + e);
e.printStackTrace();
}
// finally
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
브 라 우 저의 중국어 난 장 판 을 해결 하기 위해 서 Vert. x 는 인 코딩 을 추가 해 야 하고 인 코딩 방식 은 GBK 여야 합 니 다.
router.get("/" + urlName).handler(event -> event.response().putHeader("content-type", "text/html").end(result, "GBK"));
이 때 URLConnection 을 사용 하여 결 과 를 분석 할 때 기본 디 코딩 을 사용 하면 난해 합 니 다. GBK 디 코딩 방식 을 사용 해 야 합 니 다.
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "GBK"));
브 라 우 저 에서 중국어 가 어 지 럽 지 않 고 테스트 하기 편리 하도록 보장 합 니 다.자바 코드 를 통 해 중국어 가 어 지 럽 지 않 고 사용 할 수 있 도록 요청 합 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Vert.x3 시작~웹 응용 프레임워크 Apex이번에 우리는 간단한 REST 서버를 이동하기 위해 공식 웹 응용 프레임워크 를 사용할 것이다. 미리 Java8을 설치하십시오.다음 명령을 사용하여 Java8이 설치되었는지 확인할 수 있습니다. IntelliJ를 시...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.