我正在通过Android上的排球库向网页发送请求,该网址包含一些阿拉伯语字符,但在php文件中我收到了问号而不是我的问号阿拉伯语字母(??????),我尝试了人们在网上说的解决方案,但所有人都试图从网上读取数据,因为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;
}
};
答案 0 :(得分:1)
您需要先编码您的网址,然后才能在您的请求中使用它。 见http://istizada.com/understanding-arabic-url-uri-structure-encoding-for-arabic-sites/