I am developing an Android application in which a user can register by choosing Hindi and English. It works great when sending to English, but when sending Hindi text, I get text in t format %E0%A4%A6%E0%A4%95%E0%A4%97in the table. I tried to put the encoding for the header, but it does not work.
The code I use
URL url = new URL(Config.ORGANISATION_DETAILS_URL);
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Accept-Charset", "UTF-8");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;charset=utf-8;boundary=" + boundary);
conn.setRequestProperty("uploaded_file", fileName);
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
String str=nameoforget.getText().toString();
String nameoforg=URLEncoder.encode(str, "UTF-8");
dos.writeBytes("Content-Disposition: form-data; name=\"nameoforg\"" + lineEnd);
dos.writeBytes(lineEnd);
dos.writeBytes(nameoforg);
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
String noofstudents=""+noofstdset.getText().toString();
dos.writeBytes("Content-Disposition: form-data; name=\"noofstudents\"" + lineEnd);
dos.writeBytes(lineEnd);
dos.writeBytes(noofstudents);
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\"" + fileName + "\"" + lineEnd);
dos.writeBytes(lineEnd);
if(sourceFileUri!=null)
{
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
}
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
Thanks at Advance ..
source
share