Volley 以 utf-8 格式发送请求

Volley sending request as utf-8

我正在通过 android 上的 volley 库向 Web 发送请求,其中包含 Arabic 字符 URL ,但是在 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;
    }
};

您需要先对 url 进行编码,然后才能在您的请求中使用它。 参见 http://istizada.com/understanding-arabic-url-uri-structure-encoding-for-arabic-sites/