Java模拟post请求
来源:互联网 发布:js如何修改元素属性值 编辑:程序博客网 时间:2024/05/17 02:47
private String getApiReply(){
String responseStr="";
try{
URL url = new URL("http://www.****");
HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-type", "application/json");
//httpConn.s
httpConn.setDoOutput(true);
StringBuffer xml=new StringBuffer();
byte[] b = xml.toString().getBytes();//和get的方法一样的
httpConn.getOutputStream().write(b, 0, b.length);
httpConn.getOutputStream().flush();
httpConn.getOutputStream().close();
//获得服务器返回的数据
InputStreamReader l_urlStream = new InputStreamReader(httpConn.getInputStream(), "UTF-8");
BufferedReader l_reader = new BufferedReader(l_urlStream);
String sCurrentLine="";
while ((sCurrentLine = l_reader.readLine()) != null) {
responseStr += sCurrentLine;
}
}catch(Exception e){
e.printStackTrace();
}
return responseStr;
}
String responseStr="";
try{
URL url = new URL("http://www.****");
HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-type", "application/json");
//httpConn.s
httpConn.setDoOutput(true);
StringBuffer xml=new StringBuffer();
byte[] b = xml.toString().getBytes();//和get的方法一样的
httpConn.getOutputStream().write(b, 0, b.length);
httpConn.getOutputStream().flush();
httpConn.getOutputStream().close();
//获得服务器返回的数据
InputStreamReader l_urlStream = new InputStreamReader(httpConn.getInputStream(), "UTF-8");
BufferedReader l_reader = new BufferedReader(l_urlStream);
String sCurrentLine="";
while ((sCurrentLine = l_reader.readLine()) != null) {
responseStr += sCurrentLine;
}
}catch(Exception e){
e.printStackTrace();
}
return responseStr;
}
0 0
- Java模拟post请求
- JAVA模拟POST请求
- Java模拟Post请求
- JAVA模拟post请求
- java 模拟post请求
- Java模拟post请求
- java模拟post请求
- java 模拟post请求
- java模拟get/post请求
- java类模拟浏览器post请求
- 用java代码模拟post请求
- 使用java模拟Get与Post请求
- java模拟post请求上传文件
- Java 后台模拟发送 POST GET 请求
- Java利用Http 模拟POST、GET请求
- java模拟HTTP post,get请求
- Java模拟Http post、get请求
- Java实现模拟发送POST、GET请求
- 学习php需要了解的点1
- 多普勒失真信号重采样的Matlab仿真分析
- 2014 (多校)1011 ZCC Loves Codefires
- Android系统手机内部文件夹架构及其各文件的功能解析
- ArcGIS ArcSDE将数据注册或取消注册为版本快速浏览
- Java模拟post请求
- 如何编写C++软件
- 数列有序!(2019)
- iScroll4插件的使用实例
- MFC中CString.Format的详细用法
- Swift源码分析----swift-object-auditor(1)
- 导入三方包,出现ClassNotFoundException
- hdu 4217Data Structure?
- 做好投资理财 巧减都市压力