java - 使用 http 请求 GET android 发送阿拉伯语单词

标签 java android android-asynctask

我想通过 HTTP 请求发送阿拉伯语(unicode)

当使用URLEncodedUtils.format(params, HTTP.UTF_8); 当单词是阿拉伯语时,它会给出 paramString 这个值 “%D8%A7%D9%84%D9%82%D8%A7%D9%87%D8%B1%D9%87”

这是我的代码:

DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, HTTP.UTF_8);

Log.d("Parser" , paramString);
url += "?" + paramString;
Log.d("parser" , url);
HttpGet httpGet = new HttpGet(url);

HttpResponse httpResponse = httpClient.execute(httpGet);

HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

服务器代码

function getShippingAddress($email)
   {
            $customerAddress = Mage::getModel('customer/address');
            $customer = Mage::getModel('customer/customer');
            $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
            $customer->loadByEmail($email);
            $defaultShippingId = $customer->getDefaultShipping();
            $customerAddress->load($defaultShippingId); 
            $response["success"] = 1;
            $response["data"][0] = $customerAddress->getData('city');
            $response["data"][1] = $customerAddress-  >getData('street');
            $response["data"][2] = $customerAddress->getData('telephone');


        header('Content-Type: application/json; charset=utf-8');
        return json_encode($response);
}

最佳答案

尝试使用 POST 发送参数。示例代码在这里:

private String sendHttpPost(String url, String msg)
        throws Exception {

    HttpPost post = new HttpPost(url);

    StringEntity stringEntity = new StringEntity(msg, "UTF-8");
    post.setEntity(stringEntity);


    return execute(post);
}

或者试试这个:

String unicodeUrl = URLEncoder.encode(url += "?" + paramString, "UTF-8");
HttpPost post = new HttpPost(unicodeUrl);

更新:

如果您的参数 =“Some_String_In_Arabic”,请尝试以下代码:

DefaultHttpClient httpClient = new DefaultHttpClient();
//String paramString = URLEncodedUtils.format(params, HTTP.UTF_8);

String unicodeUrl = URLEncoder.encode(url += "?" + params, "UTF-8");
Log.d("URL" , unicodeUrl);
HttpGet httpGet = new HttpGet(unicodeUrl);

HttpResponse httpResponse = httpClient.execute(httpGet);

HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

并在服务器端使用(PHP 的)urldecode 方法将字符串恢复为阿拉伯语形式。

关于java - 使用 http 请求 GET android 发送阿拉伯语单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36126762/

相关文章:

android代码拨出号码暂停

android - getRotation 的结果在 Android 中并不精确

java - 将 AsyncTask 从类中调用到 MainActivity 中

android - 检查服务器上是否存在 URL

java - 如何在Java中解密私钥(不使用BC openssl)

java - 如何在不刷新android应用程序的情况下从数据库获取数据?

java - TomEE 中的 ManagedScheduledExecutorService

Android fragment 相互重叠

java - 将 Hashmap 写入文件

java - 如何在使用 Selenium 驱动程序执行 Foreach 循环时对其进行控制?