80,471
社区成员




HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(strUrl);
StringEntity entity = new StringEntity(json);
entity.setContentType("application/json");
entity.setContentEncoding("utf-8");
post.setEntity(entity);
HttpResponse responString = client.execute(post);
try {
BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream()));
String line = "";
StringBuilder sb = new StringBuilder();
while((line = br.readLine())!=null){
sb.append(line);
}
System.out.println("diaryjson:"+sb.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("diaryjson receive failure!!!!");
}
public String MakeDiaryJson(String title,String context,String createtime,String lastmodifytime, int user_id) throws Exception{
String diaryjson="";
JSONObject json = new JSONObject();
try {
//diary中存入日记标题
json.put("title", title);
//diary中存入日记内容
json.put("context", context);
//diary中存入日记创建时间
json.put("createtime", createtime);
//diary中存入日记最后一次修改时间
json.put("lastmodifytime", lastmodifytime);
//diary中存入日记外键,就是这篇日记是属于哪个用户的
json.put("user_id", user_id);
diaryjson = json.toString();
URLDecoder.decode(diaryjson,"utf-8");
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.i("JSonInfo:", "MakeDiaryJson create failure!!!!");
}
return URLDecoder.decode(diaryjson,"utf-8");
};
服务器的代码:
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("execute()方法被执行了!!!");
try {
BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream()));
String line = "";
StringBuilder sb = new StringBuilder();
while((line = br.readLine())!=null){
sb.append(line);
}
System.out.println("diaryjson:"+URLDecoder.decode(sb.toString(),"utf-8"));
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("diaryjson receive failure!!!!");
}
[/quote]
return URLDecoder.decode(diaryjson,"utf-8");//这句是解码代码,发送时用编码
[/quote]
用什么编码?是用encodeuricomponent()?
public String MakeDiaryJson(String title,String context,String createtime,String lastmodifytime, int user_id) throws Exception{
String diaryjson="";
JSONObject json = new JSONObject();
try {
//diary中存入日记标题
json.put("title", title);
//diary中存入日记内容
json.put("context", context);
//diary中存入日记创建时间
json.put("createtime", createtime);
//diary中存入日记最后一次修改时间
json.put("lastmodifytime", lastmodifytime);
//diary中存入日记外键,就是这篇日记是属于哪个用户的
json.put("user_id", user_id);
diaryjson = json.toString();
URLDecoder.decode(diaryjson,"utf-8");
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.i("JSonInfo:", "MakeDiaryJson create failure!!!!");
}
return URLDecoder.decode(diaryjson,"utf-8");
};
服务器的代码:
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("execute()方法被执行了!!!");
try {
BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream()));
String line = "";
StringBuilder sb = new StringBuilder();
while((line = br.readLine())!=null){
sb.append(line);
}
System.out.println("diaryjson:"+URLDecoder.decode(sb.toString(),"utf-8"));
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("diaryjson receive failure!!!!");
}
[/quote]
return URLDecoder.decode(diaryjson,"utf-8");//这句是解码代码,发送时用编码
public String MakeDiaryJson(String title,String context,String createtime,String lastmodifytime, int user_id) throws Exception{
String diaryjson="";
JSONObject json = new JSONObject();
try {
//diary中存入日记标题
json.put("title", title);
//diary中存入日记内容
json.put("context", context);
//diary中存入日记创建时间
json.put("createtime", createtime);
//diary中存入日记最后一次修改时间
json.put("lastmodifytime", lastmodifytime);
//diary中存入日记外键,就是这篇日记是属于哪个用户的
json.put("user_id", user_id);
diaryjson = json.toString();
URLDecoder.decode(diaryjson,"utf-8");
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.i("JSonInfo:", "MakeDiaryJson create failure!!!!");
}
return URLDecoder.decode(diaryjson,"utf-8");
};
服务器的代码:
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("execute()方法被执行了!!!");
try {
BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream()));
String line = "";
StringBuilder sb = new StringBuilder();
while((line = br.readLine())!=null){
sb.append(line);
}
System.out.println("diaryjson:"+URLDecoder.decode(sb.toString(),"utf-8"));
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("diaryjson receive failure!!!!");
}
System.out.println("diaryjson:"+URLDecoder.decode(sb.toString(),"utf-8"));