- 浏览: 329907 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (350)
- JAVAEE (155)
- Gwt (27)
- Android (6)
- TaoBao (0)
- Xiaonei (0)
- Ubuntu (1)
- javafx (1)
- flex (0)
- GAE (2)
- Arcgis (1)
- Extjs (5)
- Dwr (1)
- ExtjsDwrSpring整合 (2)
- ophone (0)
- php (1)
- python (8)
- squid for windows download (1)
- Java (3)
- oracle (1)
- jquery (1)
- 淘宝 (1)
- 人生 (0)
- java项目运行时增加 (1)
- xfire (1)
- jquery mobile (1)
- ES (3)
- logstash (2)
- 8080端口占用 (1)
- 通达信 (1)
- mysql启动故障 (1)
- 微信小程序 (3)
- centos (1)
- redis (1)
- springcloud (1)
- python3.9 (1)
- python2.7 (1)
- ta-lib (0)
- ta-lib,TALIB (1)
- 安装TALIB,CENTOS (1)
- 终端关闭后 (1)
- vi (1)
- 命令行 (1)
- tomcat (2)
- nginx (3)
- linux (2)
- jdk (1)
- 开发环境 (1)
- nodejs (1)
- vs code (1)
- node js 全部版本 (1)
- JAVASCRIPT (1)
- pychar (1)
- mysql (3)
- win10 (1)
- elasticsearch plugin (1)
- vue (10)
- editplus (0)
- clickhouse (6)
- zabbix (1)
- quicktracking (1)
- quiktraking (1)
- talib (1)
- docker (1)
- excel (1)
- bat (1)
最新评论
-
ian_jiang:
不知道 你说了个 什么?
GWT下如何获取到javaee servlet下会话信息 -
心愿:
index.jsp应该建立在哪个目录下
dwr3.0的HELLOWORLD创建过程 -
349446658:
classpath:path是老的指定配置文件路径的方式。升级 ...
升级2 -
349446658:
新版本不是在type中指定first,而是指定1来表示跳到第一 ...
分页错误2 -
349446658:
这是因为后面的版本规范了指定配置文件路径的方式,必须指定为如下 ...
升级错误
package com.arpenker.stockrobot.dingding;
import com.alibaba.fastjson.JSON;
//import com.sun.org.slf4j.internal.Logger;
//import com.sun.org.slf4j.internal.LoggerFactory;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
* @Author: zhouhe
* @Date: 2019/6/20 14:49
*/
public class SendHttps {
// private static Logger logger = LoggerFactory.getLogger(SendHttps.class);
/**
* 发送POST请求,参数是Map, contentType=x-www-form-urlencoded
*
* @param url
* @param mapParam
* @return
*/
public static String sendPostByMap(String url, Map<String, Object> mapParam) {
Map<String, String> headParam = new HashMap();
headParam.put("Content-Type", "application/json;charset=utf-8");
// 设置通用的请求属性 请求头
headParam.put("accept", "*/*");
headParam.put("connection", "Keep-Alive");
headParam.put("user-agent",
"Fiddler");
return sendPost(url, mapParam, headParam);
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,
* @return 所代表远程资源的响应结果
*/
public static String sendPost(String url, Map<String, Object> param, Map<String, String> headParam) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性 请求头
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty( "Content-Type","application/json ;charset=utf-8 ");
conn.setRequestProperty("user-agent",
"Fiddler");
if (headParam != null) {
for (Entry<String, String> entry : headParam.entrySet()) {
conn.setRequestProperty(entry.getKey(), entry.getValue().toString());
}
}
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(JSON.toJSONString(param));
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
// logger.info("发送 POST 请求出现异常!" + e);
e.printStackTrace();
}
//使用finally块来关闭输出流、输入流
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
}
import com.alibaba.fastjson.JSON;
//import com.sun.org.slf4j.internal.Logger;
//import com.sun.org.slf4j.internal.LoggerFactory;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
* @Author: zhouhe
* @Date: 2019/6/20 14:49
*/
public class SendHttps {
// private static Logger logger = LoggerFactory.getLogger(SendHttps.class);
/**
* 发送POST请求,参数是Map, contentType=x-www-form-urlencoded
*
* @param url
* @param mapParam
* @return
*/
public static String sendPostByMap(String url, Map<String, Object> mapParam) {
Map<String, String> headParam = new HashMap();
headParam.put("Content-Type", "application/json;charset=utf-8");
// 设置通用的请求属性 请求头
headParam.put("accept", "*/*");
headParam.put("connection", "Keep-Alive");
headParam.put("user-agent",
"Fiddler");
return sendPost(url, mapParam, headParam);
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,
* @return 所代表远程资源的响应结果
*/
public static String sendPost(String url, Map<String, Object> param, Map<String, String> headParam) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性 请求头
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty( "Content-Type","application/json ;charset=utf-8 ");
conn.setRequestProperty("user-agent",
"Fiddler");
if (headParam != null) {
for (Entry<String, String> entry : headParam.entrySet()) {
conn.setRequestProperty(entry.getKey(), entry.getValue().toString());
}
}
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(JSON.toJSONString(param));
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
// logger.info("发送 POST 请求出现异常!" + e);
e.printStackTrace();
}
//使用finally块来关闭输出流、输入流
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
}
发表评论
-
SpringCloud00 _Restemplate的getForEntity、getForObject、 postForEntity、postForObjec
2022-10-20 02:26 142SpringCloud00 _Restemplate的get ... -
java键盘机器人
2022-08-18 16:26 162package com.yuexiu.yxdp.rpt.be ... -
java常用快捷键
2022-08-18 15:47 184IDEA中常用快捷键 psvm —— 用来快速写一个ma ... -
idea在旧环境里安装又出这个问题了
2022-08-11 17:33 2406这个一眼就看出来是找不到jre的错误。关键 ... -
mysql 5.5的安装包官网下载地址
2022-07-07 21:09 393https://downloads.mysql.com/arc ... -
idea java开发快捷键
2022-07-07 15:02 170在dao层的mapper类里。直接按住ctrl+左键可定位.x ... -
plugin
2022-07-05 10:45 164INFO] Finished at: 2022-07-05T1 ... -
maven配置,通用setting.xml配置-改为阿里云
2022-07-04 10:50 547maven配置,通用setting.xml配置-改为阿里云 ... -
启动模块时报错,命令行过长,command is too long.
2022-07-04 06:42 1165启动模块时报错,命令行过长,command is too lo ... -
node js 全部版本
2022-07-01 10:58 2549https://nodejs.org/en/download/ ... -
post json
2022-07-01 08:00 136try { String ding ... -
resttemplate
2022-06-30 15:21 179private static ResponseEntity&l ... -
量化工
2022-06-30 09:54 530String url = "https://api. ... -
eclipse快捷键
2022-06-30 09:18 197package shortcutKey; public cl ... -
ideajdk
2022-06-10 08:06 171「ideajdk」https://www.aliyundriv ... -
nohup java
2022-05-30 19:02 598nohup java -jar test.jar > . ... -
nohup java
2022-05-30 18:36 769springboot 项目内嵌tomcat,一般打包成jar ... -
查服务器硬盘内存CPU
2022-05-25 17:31 270grep MemTotal /proc/meminfo # ... -
tomcat8 和 jdk8
2022-05-21 08:06 213「tomcat8jdk8」https://www.aliyu ... -
Node Sass does not yet support your current environment: Windows 64-bit问题解决办法
2022-05-17 13:18 692Node Sass does not yet support ...
相关推荐
postjson_windows接口测试工具,本地、在线都可以测试!
利用c# httpclient ,post json数据到web api
安卓http post json 方法
C#写的Html帮助类 有线程下载 图片下线 GET POST JSON等
Retrofit2 登录Demo @Post json数据到服务器 addConverterFactory(GsonConverterFactory.create()) 把服务端返回的json数据解析成实体的ApiResult<ApiToken>
Qt 实现的http请求,采用POST 方式 ,上传json数据内容的个人测试工具,支持中文转UTF-8的接口
原生asp.net不支持通过json提交 方式给控制器的Action传参数,本程序通过给自定义输入字符串格式方法。在action的传参上加入FromJsonKey属性即可在传入的json中传入参数,如果传入的json中不存在相应键即报错 ...
delphixe10.2写的Http Post Json格式数据的例子.使用线程发送,很好用.
post\get接口压力测试
HTTP Post提交与接收Json Winform程序,实现Json的提交和接收
java http-post json格式客户端请求代码
tiny-json-http:极简的HTTP客户端用于GET和POST JSON 负载
C#通过post提交json字符串示例
Okhttp框架post json封装
POSTJSON支持ACCESS、Mysql、Mssql自动生成JSON,提交到服务器接口,自定义发送数据sql和服务器接收地址,是单机数据库向服务器提交汇总工具,定时提交开发中。
利用HTTP控件 和RESTClient控件,编写的POST JSON示例,有客户端(HTTP和RESTClient分别实现)和服务端,也可以向在线网站进行测试。
今天小编就为大家分享一篇php post json参数的传递和接收处理方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
post json 请求