How do i send the Hindi text to php server by using HttpUrlConnection in Android -
i'm developing android application in user can register choosing hindi , english language. working fine while sending in english while sending hindi text i'm getting unknown format text %e0%a4%a6%e0%a4%95%e0%a4%97
in table.i have tried put encoding header not working.
the code i'm using
url url = new url(config.organisation_details_url); // open http connection url conn = (httpurlconnection) url.openconnection(); conn.setdoinput(true); // allow inputs conn.setdooutput(true); // allow outputs conn.setusecaches(false); // don't use cached copy 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("expect", "100-continue"); conn.setrequestproperty("uploaded_file", filename); dos = new dataoutputstream(conn.getoutputstream()); dos.writebytes(twohyphens + boundary + lineend); //adding parameter name of organisation string str=nameoforget.gettext().tostring(); string nameoforg=urlencoder.encode(str, "utf-8"); //string nameoforg=str; dos.writebytes("content-disposition: form-data; name=\"nameoforg\"" + lineend); //dos.writebytes("content-type: text/plain; charset=utf-8" + lineend); //dos.writebytes("content-length: " + nameoforg.length() + lineend); dos.writebytes(lineend); dos.writebytes(nameoforg); // mobile_no string variable dos.writebytes(lineend); dos.writebytes(twohyphens + boundary + lineend); string noofstudents=""+noofstdset.gettext().tostring(); dos.writebytes("content-disposition: form-data; name=\"noofstudents\"" + lineend); //dos.writebytes("content-type: text/plain; charset=utf-8" + lineend); //dos.writebytes("content-length: " + noofstudents.length() + lineend); dos.writebytes(lineend); dos.writebytes(noofstudents); // mobile_no string variable dos.writebytes(lineend); dos.writebytes(twohyphens + boundary + lineend); /*to upload file*/ dos.writebytes("content-disposition: form-data; name=\"uploaded_file\";filename=\"" + filename + "\"" + lineend); dos.writebytes(lineend); if(sourcefileuri!=null) { // create buffer of maximum size bytesavailable = fileinputstream.available(); buffersize = math.min(bytesavailable, maxbuffersize); buffer = new byte[buffersize]; // read file , write form... 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); } } // send multipart form data necesssary after file data... dos.writebytes(lineend); dos.writebytes(twohyphens + boundary + twohyphens + lineend);
thanks in advance..
how send hindi text or other encoded text php server using httpurlconnection in android
after searching in google got solution question. before sending data encoded string urlencoder.encode() in java class. following code in java
in java:
string nameoforg=urlencoder.encode("हिन्दी", "utf-8"); dos.writebytes("content-disposition: form-data; name=\"nameoforg\"" + lineend); dos.writebytes(nameoforg); dos.writebytes(lineend); dos.writebytes(twohyphens + boundary + lineend);
and in php when receive post data android need decode post data.for example
in php:
$nameoforg=$_post['nameoforg']; $nameoforg=urldecode($nameoforg); echo $nameoforg;
that's it...now can store same data in database php.
Comments
Post a Comment