如何在Android中使用HttpUrlConnection将印地语文本发送到php服务器

如何在Android中使用HttpUrlConnection将印地语文本发送到php服务器,php,android,Php,Android,我正在开发一个Android应用程序,用户可以通过选择印地语和英语进行注册。用英语发送时,它工作正常,但在发送印地语文本时,我得到了未知格式的文本%E0%A4%A6%E0%A4%95%E0%A4%97。我已尝试将标题的编码放在表中,但它不起作用 我正在使用的代码 URL url = new URL(Config.ORGANISATION_DETAILS_URL); // Open a HTTP connection to the URL conn = (HttpURLConnection)

我正在开发一个Android应用程序,用户可以通过选择印地语和英语进行注册。用英语发送时,它工作正常,但在发送印地语文本时,我得到了未知格式的文本
%E0%A4%A6%E0%A4%95%E0%A4%97
。我已尝试将标题的编码放在表中,但它不起作用

我正在使用的代码

URL url = new URL(Config.ORGANISATION_DETAILS_URL);

// Open a HTTP  connection to  the URL
conn = (HttpURLConnection) url.openConnection(); 
conn.setDoInput(true); // Allow Inputs
conn.setDoOutput(true); // Allow Outputs
conn.setUseCaches(false); // Don't use a 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 is 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 is 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 a buffer of  maximum size
    bytesAvailable = fileInputStream.available(); 

    bufferSize = Math.min(bytesAvailable, maxBufferSize);
    buffer = new byte[bufferSize];

    // read file and write it into 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);

提前感谢。

如何在Android中使用HttpUrlConnection将印地语文本或其他编码文本发送到Php服务器

    After searching in google i got the solution for my question. Before sending the data I Encoded the String with URLEncoder.encode() in java class. The following code is in java
在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);
现在在PHP中,当我们从Android接收Post数据时,我们需要解码Post数据

在Php中:

    $nameoforg=$_POST['nameoforg'];
    $nameoforg=urldecode($nameoforg);
    echo $nameoforg;
就是这样…现在您可以从php在数据库中存储相同的数据

显示印地语 在点击服务器时调用此方法

encodeString(your hindi or english string)

public static String encodeString(String str) throws UnsupportedEncodingException {
  return URLEncoder.encode(str, "UTF-16");
}
从服务器获得响应后调用此方法

decodeString(your server string)

public static String decodeString(String str) throws UnsupportedEncodingException {
    return URLDecoder.decode(str, "UTF-16");
}

这似乎是相当多的代码。您是否可以编辑您的问题,使其仅包含一个“请”?假设能够回答你问题的人是那些没有时间阅读超过10行代码的人的子集。你在MySql中保存android数据的表的排序规则是什么?嗨,Wai Ha Lee,谢谢你的回答,我是这个网站的新手。现在我的疑问是我想使用HttpURLconnection将印地语文本发送到Php文件。在发送之前,我正在使用URLEncoder.encode(str,“UTF-8”)进行解码,尽管它显示为“%E0%A4%A6%E0%A4%95%E0%A4%97”。嗨,eurosecom,我的问题是在将数据存储到数据库之前,我的意思是,当我尝试在Php中从Android向Php发送印地语文本时,印地语文本显示为“%E0%A4%A6%E0%A4%95%E0%A4%97”。我如何发送印地语数据?