我的URL中有一些使用StringRequest类发送的Unicode字符。一旦我在服务器上获得它们,它们就不能以正确的格式表示。我从服务器接收数据时遇到了同样的问题,通过覆盖parseNetworkResponse方法解决了这个问题。我该怎么办?
StringRequest request = new StringRequest(Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// ...
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
}
}) {
@Override
protected Response<String> parseNetworkResponse(
NetworkResponse response) {
// TODO Auto-generated method stub
String strUTF8 = null;
try {
strUTF8 = new String(response.data, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Response.success(strUTF8,
HttpHeaderParser.parseCacheHeaders(response));
}
public java.util.Map<String, String> getHeaders()
throws com.android.volley.AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
return headers;
}
};
答案 0 :(得分:1)
假设阿拉伯语是一个字符串,为什么不试试这个:
URI.encode("10.0.2.2/test.php?key=20893&rt=add&w1='تست'&w2='تست'").