我想用HTTP请求发送阿拉伯语(unicode)
当使用URLEncodedUtils.format(params, HTTP.UTF_8);
时,如果单词是阿拉伯语“%D8%A7%D9%84%D9%82%D8%A7%D9%87%D8%B1%D9%87”,则paramString
将获得此值
这是我的代码:
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);
}
2条答案
按热度按时间7qhs6swi1#
尝试使用POST发送参数。示例代码如下:
或者试试这个:
更新:
如果你的params =“Some_String_In_Arabic”,尝试以下代码:
然后在服务器端使用urldecode方法(PHP的)以阿拉伯语形式获取字符串。
snvhrwxg2#
'search':“${utf8.encode(searching)}",
如果您正在获取Failed to read the 'headers' property from 'RequestInit':字符串包含非ISO-8859-1代码点。
如果您使用多种语言搜索,如果您使用英语以外的语言,则会出现ISO错误,因此您必须将其编码到客户端并在服务器端解码以获得结果