我正在通过以下方式向网络发送请求volleyandroid 上的库包含一些ArabicURL中的字符,但是在php文件中我得到了问号而不是阿拉伯字母(??????),我尝试了人们在网上所说的解决方案,但所有这些都尝试从网络读取数据as UTF-8 不以 UTF-8 形式发送数据。
这是我的代码:
String url = "http://mywebsite.com/file.php?parameter=سلام"
JsonObjectRequest request = new JsonObjectRequest(Method.GET, url, null, new Listener<JSONObject>(){
@Override
public void onResponse(JSONObject response)
{
try
{
if(response.has("result") && response.getBoolean("result"))
{
prefs.edit().putBoolean(Launcher.REGISTERED_KEY, true).apply();
Intent intent = new Intent(Subscribe.this, Home.class);
Toast.makeText(Subscribe.this, R.string.register_success_message, Toast.LENGTH_LONG).show();
startActivity(intent);
Subscribe.this.finish();
}
else
{
msgBox.setText(R.string.subscribtion_error);
}
}
catch(Exception e)
{
msgBox.setText(R.string.subscribtion_error);
e.printStackTrace();
}
}
}, new ErrorListener(){
@Override
public void onErrorResponse(VolleyError error)
{
msgBox.setText(R.string.subscribtion_error);
Log.e("", error.toString());
}
}){
/**
* Passing some request headers
* */
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
您需要先对 url 进行编码,然后才能在请求中使用它。
看http://istizada.com/understanding-arabic-url-uri-struct-encoding-for-arabic-sites/ http://istizada.com/understanding-arabic-url-uri-structure-encoding-for-arabic-sites/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)