Android利用JSON发送数据到服务器
来源:互联网 发布:电信免流软件 编辑:程序博客网 时间:2024/05/17 13:46
Android利用JSON发送数据到服务器
new Thread()
{
@Override
public void run() {
// TODO Auto-generated method stub
Looper.prepare();
final String urlPath="http://60.176.36.125:8080/wms/resisteruser.do";
URL url;
try
{
url = new URL(urlPath);
/*封装子对象*/
JSONObject ClientKey = new JSONObject();
ClientKey.put("appusername", userName.getText().toString());
ClientKey.put("passwd", passWord.getText().toString());
ClientKey.put("eigenvalues", eigenValues.getText().toString());
ClientKey.put("telephone", phoneNum.getText().toString());
ClientKey.put("apprealname", realName.getText().toString());
ClientKey.put("email", emailNum.getText().toString());
ClientKey.put("sex", sex);
/*封装Person数组*/
JSONObject params = new JSONObject();
params.put("Person", ClientKey);
/*把JSON数据转换成String类型使用输出流向服务器写*/
String content = String.valueOf(params);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setDoOutput(true);//设置允许输出
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent", "Fiddler");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Charset", encoding);
OutputStream s = conn.getOutputStream();
os.write(content.getBytes());
os.close();
/*服务器返回的响应码*/
int code = conn.getResponseCode();
if(code == 200)
{
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), encoding));
String retData = null;
String responseData = "";
while((retData = in.readLine()) != null)
{
responseData += retData;
}
JSONObject jsonObject = new JSONObject(responseData);
JSONObject succObject = jsonObject.getJSONObject("regsucc");
//System.out.println(result);
String success = succObject.getString("id");
in.close();
//System.out.println(success);
Toast.makeText(Register.this, success, Toast.LENGTH_SHORT).show();
Intent intentToLogin=new Intent();
intentToLogin.setClass(Register.this,Login.class);
startActivity(intentToLogin);
finish();
}
else
{
Toast.makeText(getApplicationContext(), "数据提交失败", Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
// TODO: handle exception
throw new RuntimeException(e);
}
Looper.loop();
}
}.start();
- Android利用JSON发送数据到服务器
- Android利用JSON发送数据到服务器
- Android利用JSON发送数据到服务器
- 发送JSON数据到服务器
- android 发送json 到服务器
- android 发送json 到服务器
- android发送json数据到服务器(框)
- Android利用HttpClient发送Json到后台
- android 利用socket 发送Json数据demo
- Android使用JSON想服务器发送数据
- android发送json数据到服务端
- Android 发送json数据到servlet
- android,post发送数据到服务器
- android, httpclient,get,发送数据到服务器
- android,HttpPost发送数据到服务器
- golang post发送application/json数据到服务器
- 发送数据到服务器
- android 发送json 到服务器 spring 怎么接收?
- 整理音乐
- LeetCode OJ 之 Path Sum(求路径和)
- dalvikvm, dvz app_process
- C++11 lambda表达式
- 那些年,我踩过的坑,而后人绝不要再踩
- Android利用JSON发送数据到服务器
- HDU2132 An easy problem 【Java】
- java 处理html代码 中<p> 标签 保证闭合
- [JAVA] 文本分段处理,中文
- shell中的变量
- 安卓客户端与服务器端交互
- 软件开发合同纠纷的律师随笔
- 记录几款网络抓包工具
- Android中使用WebView去构建一个简单的web app.