douyannuo7733 2015-03-27 19:51
浏览 33
已采纳

如何将url中的阿拉伯语文本作为参数从android app发送到php webservice

I want to add search function in my android app, but the problem is when i add arabic parameter to url e.g("example.com?q=بلد") it gives null result. although if i add text manually in browser to url it works fine.

        InputStream inputStream = null;
        String contentAsString = null;
        try {
            URL url = new URL("example.com?q=بلد");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            inputStream = conn.getInputStream();
            contentAsString = readIt(inputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

PHP code

    header('Content-Type: text/html; charset=utf-8');

    mysql_select_db($this->get_databaseName(), $this->con);
    mysql_query("SET NAMES 'utf8'");
    mysql_query('SET CHARACTER SET utf8');

    $query="Select * from tbl_posts where post_title=".$_GET['q']";

Data base table field encoding method is utf8_general_ci

In simple words i want to add some arabic text as parameter in url, through which i can query database using php web service.

  • 写回答

3条回答 默认 最新

  • duanao4729 2015-03-27 19:57
    关注

    While sending such kind of special characters to server you need to encode such input with the help of URLEncoder.encode(your_input, "utf-8") and while receiving such kind of data first of all you need to decode it with the help of URLDecoder.decode(your_data, "utf-8")

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解