标签:
private void doVolley(){
RequestQueue mRequestQueue = Volley.newRequestQueue(getActivity());
StringRequest mStringRequest = new StringRequest(
"http://www.baidu.com",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
String s = response;
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDefaultTextEncodingName("utf-8");
mWebView.loadDataWithBaseURL(null,s,"text/html","utf-8",null);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mWebView.loadDataWithBaseURL(null,"失败","text/html","utf-8",null);
}
}
){
//这是重写的方法,源代码默认是外国人用的ISO-8859-1,现在改成utf-8格式
@Override
protected Response<String> parseNetworkResponse(
NetworkResponse response) {
try {//jsonObject要和前面的类型一致,此处都是String
String jsonObject = new String(
new String(response.data, "UTF-8"));
return Response.success(jsonObject, HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (Exception je) {
return Response.error(new ParseError(je));
}
}
};
mRequestQueue.add(mStringRequest);
}
标签:
原文地址:http://www.cnblogs.com/lyf2458857555/p/5894453.html