Android 中的 Soap 字符编码
我可以通过我在下面共享的代码调用网络服务,这没问题,但是当我使用土耳其字符向参数发送值时,出现了编码问题。当我将编码字符集 utf-8 更改为 iso-8859-9 时,一些土耳其字符会正确显示(ç、ö、ü),但 3 个字母(ı、ğ、ş)不会改变。为什么会发生这种情况?
abcçdefg*?h?*ijklmnoöprs?tuüvyz 必须是:abcçdefg*ğ*h*ı*ijklmnoöprs*ş*tuüvyz
final DefaultHttpClient httpClient=new DefaultHttpClient(); HttpParams params = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 15000);
// set parameter
HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), true);
// POST the envelope
HttpPost httppost = new HttpPost(parameters[0]);
// add headers
httppost.setHeader("soapaction", parameters[1]);
httppost.setHeader("Content-Type", "text/xml; charset=iso-8859-9");
String responseString="";
try {
HttpEntity entity = new StringEntity(parameters[2]);
httppost.setEntity(entity);
// extended class from BasicResponseHandler
ResponseHandler<String> rh=new ResponseHandlerTr();
responseString=httpClient.execute(httppost, rh);
}
catch (Exception e) {
Log.v("exception", e.toString());
}
// close the connection
httpClient.getConnectionManager().shutdown();
return responseString;
I can call webservices via the code that I am sharing below and it's ok but while I am sending a value to parameter with turkish characters there is coming up an encoding problem. When I change the encode charset utf-8 to iso-8859-9, some turkish chars get correct displayed (ç, ö, ü) but 3 letters (ı, ğ, ş) does not change. why does this happen?
abcçdefg*?h?*ijklmnoöprs?tuüvyz
must be: abcçdefg*ğ*h*ı*ijklmnoöprs*ş*tuüvyz
final DefaultHttpClient httpClient=new DefaultHttpClient(); HttpParams params = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 15000);
// set parameter
HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), true);
// POST the envelope
HttpPost httppost = new HttpPost(parameters[0]);
// add headers
httppost.setHeader("soapaction", parameters[1]);
httppost.setHeader("Content-Type", "text/xml; charset=iso-8859-9");
String responseString="";
try {
HttpEntity entity = new StringEntity(parameters[2]);
httppost.setEntity(entity);
// extended class from BasicResponseHandler
ResponseHandler<String> rh=new ResponseHandlerTr();
responseString=httpClient.execute(httppost, rh);
}
catch (Exception e) {
Log.v("exception", e.toString());
}
// close the connection
httpClient.getConnectionManager().shutdown();
return responseString;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论