求教eclipse客户端传送数据乱码问题
case 1:
user_name = name.getText().toString();
password = pass.getText().toString();
type = "student";
new ConnationThread().start();
break;
————————————————
private class ConnationThread extends Thread {
private Sevlect sevlect;
private String name,password,age,sex,tel,_id,class_id;
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
sevlect = new Sevlect();
ArrayList<NameValuePair> params1 = new ArrayList<NameValuePair>();
params1.add(new BasicNameValuePair("user_name", MainActivity.this.user_name));
params1.add(new BasicNameValuePair("password", MainActivity.this.password));
params1.add(new BasicNameValuePair("type",MainActivity.this.type));
HttpResponse mHttpResponse1 = sevlect.doPost(url, params1);
//判断是否成功
if(mHttpResponse1.getStatusLine().getStatusCode() == 200) {
String mass = null ;
try {
//获取数据
InputStream is = mHttpResponse1.getEntity().getContent();
byte[] tmp = new byte[1024];
int n = -1;
// myHandler.sendEmptyMessage(mHttpResponse1.getStatusLine().getStatusCode());
while((n = is.read(tmp)) != -1) {
Log.i("FSLog", "get rsp content登录 = " + new String(tmp, 0, n));
mass = new String(tmp,0,n);
}
JSONObject jsonObject = new JSONObject(mass);
JSONArray jsonArray = null;
Message msg = handle.obtainMessage();
if (type == "teacher") {
msg.what = TEACHER;
jsonArray = jsonObject.getJSONArray(type);
}else if (type == "student") {
msg.what = STU;
jsonArray = jsonObject.getJSONArray(type);
}else if (type == "admin") {
msg.what = ADMIN;
jsonArray = jsonObject.getJSONArray(type);
}
list = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject JS = (JSONObject) jsonArray.get(i);
if (type == "teacher") {
name = JS.getString("user_name");
password = JS.getString("password");
age = JS.getString("age");
sex = JS.getString("sex");
tel = JS.getString("tel");
_id = JS.getString("_id");
class_id = JS.getString("class_id");
}else if (type == "student") {
name = JS.getString("user_name");
password = JS.getString("password");
age = JS.getString("age");
sex = JS.getString("sex");
tel = JS.getString("tel");
_id = JS.getString("_id");
}else if (type == "admin") {
name = JS.getString("user_name");
password = JS.getString("password");
_id = JS.getString("_id");
}
list.add(name);
list.add(age);
list.add(sex);
list.add(tel);
list.add(_id);
list.add(password);
list.add(class_id);
}
msg.obj = list;
handle.sendMessage(msg);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("FSLog", e.toString());
}
}else if (mHttpResponse1.getStatusLine().getStatusCode() == 800) {
Log.e("FSLog","jkjkljkl登录");
try {
//获取数据
InputStream is = mHttpResponse1.getEntity().getContent();
byte[] tmp = new byte[1024];
int n = -1;
// myHandler.sendEmptyMessage(mHttpResponse1.getStatusLine().getStatusCode());
while((n = is.read(tmp)) != -1) {
Log.i("FSLog", "get rsp content = " + new String(tmp, 0, n));
}
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("FSLog", e.toString());
}
}
}
}
myeclipse服务端获取到的名字就是乱码(user_name = name.getText().toString();获取到的是中文)。百思不得其解。user_name=URLEncoder.encode(user_name, "utf-8");转码吧,不知道是位置不对还是,并木有什么作用,要么还是???乱码,要么就是%E5%B0%8F%E5%8D%8E。。。求指导。。。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
web服务器用的是post请求,现在主要问题就是客户端弄成utf8,不知道怎么办
要看你之前在web页面使用get方式还是post的方式,还有客户端传过来的也要是utf-8格式的才行