如果文件名包含土耳其语字符(ş,ı,ü,ü,ö,ğ),则文件不会上传到Web服务器。上传到Web服务器是在php页面上完成的。那里没有问题。它上传不包含土耳其字符(英文字母)的文件名。如何解决此问题?
private String uploadFile()
{
String responseString = null;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Config.FILE_UPLOAD_URL);
try
{
AndroidMultiPartEntity entity = new AndroidMultiPartEntity(new ProgressListener() {
@Override
public void transferred(long num) {
publishProgress((int) ((num / (float) totalSize) * 100));
} });
File kaynakDosya = new File(filePath);
entity.addPart("dosya", new FileBody(kaynakDosya));
entity.addPart("islem", new StringBody(GlobalVeri.IslemFotoVideoDosya));
totalSize = entity.getContentLength();
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity r_entity = response.getEntity();
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 200) {
responseString = EntityUtils.toString(r_entity);
} else {
responseString = "Bir hata oluştu! Http Durum Kodu: " + statusCode;
}
}
catch (ClientProtocolException e) {
responseString = e.toString();
}
catch (IOException e) {
responseString = e.toString();
}
return responseString;
}
我相信
你缺少UTF-8编码。StringBody
,将要传递的文本作为带有这些特殊字符的第一个参数,并确保在第二个参数中说它是 utf-8。取代
entity.addPart("islem", new StringBody(GlobalVeri.IslemFotoVideoDosya));
跟
entity.addPart("islem", new StringBody(GlobalVeri.IslemFotoVideoDosya, Charset.forName(HTTP.UTF_8))));