通过 HttpURLConnection 将 Utf8(波斯语)发送到服务器

Send Utf8(persian) to Server By HttpURLConnection

我要将我的信息发送到服务器 但我无法发送波斯语(波斯语)字符

请帮帮我..

给我一个示例代码

尝试使用 UTF-8 编码,这是一个如何使用编码与 POST 请求的示例:

    try {
        URL url = new URL("your url");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        conn.setDoOutput(true);

        OutputStreamWriter writer = new OutputStreamWriter(
                conn.getOutputStream(), "UTF-8");
        String request = "test data";
        writer.write(request);
        writer.flush();
        System.out.println("Code:" + conn.getResponseCode());
        System.out.println("mess:" + conn.getResponseMessage());

        String response = "";
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                conn.getInputStream(), "UTF-8"));
        String line;
        while ((line = reader.readLine()) != null) {
            response += line;
        }

        System.out.println(new String(response.getBytes(), "UTF8"));
        writer.close();
        reader.close();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }