public String insert(String query)
{
String result = "";
HttpClient httpClient = new DefaultHttpClient();
try
{
HttpPost post = new HttpPost(urlInsertString);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("sql", query));
HttpEntity entity = new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8);
post.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
post.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(post);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream inputStream = httpEntity.getContent();
BufferedReader bufReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"), 8);
StringBuilder builder = new StringBuilder();
String line = null;
while ((line = bufReader.readLine()) != null)
{
builder.append(line + "\n");
}
inputStream.close();
result = builder.toString();
}
catch (Exception e)
{
Log.e("log_tag", e.toString());
}
finally
{
httpClient.getConnectionManager().shutdown();
}
return result;
}
格式化
廣告
文章分類
廣告2
2014年11月11日 星期二
[Android程式範例] httpPost中文亂碼解決方案
請特別注意以下藍字部分
訂閱:
張貼留言
(
Atom
)
![[Android程式範例] httpPost中文亂碼解決方案 [Android程式範例] httpPost中文亂碼解決方案](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDitrr0YaoUgwW-4yuveX7Ird5RJ7J6VhsBJc0ns7RJXPOwd7yBFrUqggDFmYpePSY-kjVXFvOjjBFGIjuRGbbDcQG7msjpvgOKXm-vr0Nkl78tDlU7dqfB2TMUiXp_HXxWOIhlhGcEhU/s1600/android101.jpg)
沒有留言 :
張貼留言