Issue
i Want to send arabic (unicode) with the HTTP Request
When using URLEncodedUtils.format(params, HTTP.UTF_8);
it give paramString
this value when the words are in arabic
"%D8%A7%D9%84%D9%82%D8%A7%D9%87%D8%B1%D9%87"
This is my code:
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();
The Server Code
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);
}
Solution
Try sending parameter using POST. Sample code is here:
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);
}
or try this :
String unicodeUrl = URLEncoder.encode(url += "?" + paramString, "UTF-8");
HttpPost post = new HttpPost(unicodeUrl);
UPDATE:
if your params ="Some_String_In_Arabic", try this code :
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();
and use urldecode method (of PHP) in your server side to get the string back in arabic form.
Answered By - Arun Shankar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.