Java HttpConnection Post Json 请求接口修改密码,接收返回值
来源:互联网 发布:spool导出数据 编辑:程序博客网 时间:2024/06/01 23:34
1. 在做项目时,初次调用.net接口,利用ajax有跨域的问题,利用后台方法解决。
主要是利用 DataOutputStream out = new DataOutputStream(
connection.getOutputStream());
out.writeBytes(obj.toString());
进行参数的写入。
@RequestMapping("/updateBackUserPass")
public String updateBackUserPass(HttpServletRequest request) throws IOException {String userName=request.getParameter("Username");
String rePass=request.getParameter("Pwd");
String OldPwd=request.getParameter("OldPwd");
OldPwd="123456";
StringBuffer sb = new StringBuffer("");
try {
//创建连接
URL url = new URL("http://168.160.200.188:8081/ModifyPasHandler.ashx");
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
connection.connect();
//POST请求
DataOutputStream out = new DataOutputStream(
connection.getOutputStream());
JSONObject obj = new JSONObject();
obj.put("UserName",userName);
obj.put("Pwd",rePass);
/* obj.put("OldPwd",OldPwd);*/
System.out.println(obj.toString());
out.writeBytes(obj.toString());
out.flush();
out.close();
//读取响应
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String lines;
while ((lines = reader.readLine()) != null) {
lines = new String(lines.getBytes(), "utf-8");
sb.append(lines);
}
System.out.println(sb.toString());
reader.close();
connection.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sb.toString();
}
2.第二中方式可以利用拼出Url串进行传值访问并返回,可以进行进行接收返回值
0 0
- Java HttpConnection Post Json 请求接口修改密码,接收返回值
- java发送post请求并接收返回
- HttpConnection的post请求发送数据,接收方出现乱码
- java 通过发送json,post请求,返回json数据
- php实现post请求 接收android客户端json数据 存储数据库 并返回json
- java访问远程接口返回json数据接收
- java post json 请求
- Java Json Post 请求
- java post请求接口
- post请求传json后台接收不到
- ajax请求接收返回json数据
- JAVA 请求http接口返回json数据解析
- JAVA接口传递参数(POST),从接口接收数据(JSON)
- HTTP协议post请求返回json数据
- java接口,接收json,并且将处理结果按json的格式返回
- 初涉Ajax,以post或get方法发送数据,以json或xml形式接收服务器返回的请求
- HttpURLConnection post json 数据接口请求
- http post请求接口 传输json
- 函数组合与模式匹配
- word-break
- 尺寸规范
- Linux GUI自动化测试工具x11 GUITest in Linux x86
- 使用Python求一个全排列
- Java HttpConnection Post Json 请求接口修改密码,接收返回值
- CodeForces 372A Counting Kangaroos is Fun袋鼠口袋问题折半搜索
- 动画----补间动画
- [Cloud Computing]Mechanisms: Trusted Platform Module
- Web项目中用mybatis配置多个数据库
- 6174问题
- JAVA(五)Java选择与循环语句
- 【POJ】1328 - Radar Installation(贪心)
- lucene源码分析---8