json发送hppt请求

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import javax.servlet.http.HttpServletRequest;

import org.springframework.ui.Model;

import com.alibaba.fastjson.JSONObject;

public class httpgbkutf {
public static void getRemoteId(){
//String add_url = "http://10.20.18.55:8004/open/mhis-fwa-platform/public?access_token=4F429E6F698B4572BE6B4CD5520FFFFB";
// String add_url = "http://10.20.17.22:7001/mhis-fwa-platform/public.do?auth_token=pJokE9hWJ3QRy86zTOwnQkkkmazQfJFu9nOHwHmdinF4msD23OrZCnzlP3jBC3eSwmdYqY7lT4LTKoJlZmfTSg";
String add_url = "http://10.20.18.55:8004/open/mhis-fwa-platform/public?access_token=4F429E6F698B4572BE6B4CD5520FFFFB";
//FWA直连
// String query = "&content=%7B%22advice_details%22:%0A++%5B%7B%22amount%22:10.25,%22dose_day%22:1,%22dose_form%22:%22042%22,%22dose_unit%22:%22%22,%22invoice_project%22:%2201%22,%22medical_number%22:0,%22medical_specification%22:%221%E5%85%8B%22,%0A++%22price%22:48,%22project_code%22:%22H010102010010006%22,%22project_name%22:%22%E5%92%AA%E5%94%91%E6%96%AF%E6%B1%80%E7%BC%93%E9%87%8A%E7%89%87(%E7%9A%BF%E6%B2%BB%E6%9E%97)%22,%22recipe_no%22:%221%22,%22single_dose_number%22:1,%22single_dose_unit%22:%221%22%0A++,%22take_frequence%22:2,%22take_medical_number%22:1,%22take_medical_unit%22:%22%22,%22use_day%22:1,%22deliver_way%22:%22%22%7D%5D,%0A++%22diagnoses%22:%0A++%5B%7B%22diagnose_code%22:%22H33.001%22,%22diagnose_desc%22:%22%E5%AD%94%E6%BA%90%E6%80%A7%E8%A7%86%E7%BD%91%E8%86%9C%E8%84%B1%E7%A6%BB%22%7D,%5D,%0A++%22doctor_advice_no%22:%22%22,%22doctor_code%22:%221234%22,%22doctor_name%22:%22%E6%9D%A8%E8%BF%87%22,%22in_hosp_date%22:%2220141020%22,%22medical_dept_code%22:%22123456%22,%22medical_dept_name%22:%22%E6%80%A5%E8%AF%8A%E5%86%85%E7%A7%91%22,%0A++%22card_no%22:%22D49752662C%22,%22visit_no%22:%2200012147%22,%22visit_type%22:%222%22%7D&public_type=audit&temp=2015-11-17T03:02:46.205Z";
//通过hub连接
String query = "&auth_token=pJokE9hWJ3QRy86zTOwnQkkkmazQfJFu9nOHwHmdinF4msD23OrZCnzlP3jBC3eSwmdYqY7lT4LTKoJlZmfTSg&content=%7B%22advice_details%22:%0A++%5B%7B%22amount%22:10.25,%22dose_day%22:1,%22dose_form%22:%22042%22,%22dose_unit%22:%22%22,%22invoice_project%22:%2201%22,%22medical_number%22:0,%22medical_specification%22:%221%E5%85%8B%22,%0A++%22price%22:48,%22project_code%22:%22H010102010010006%22,%22project_name%22:%22%E5%92%AA%E5%94%91%E6%96%AF%E6%B1%80%E7%BC%93%E9%87%8A%E7%89%87(%E7%9A%BF%E6%B2%BB%E6%9E%97)%22,%22recipe_no%22:%221%22,%22single_dose_number%22:1,%22single_dose_unit%22:%221%22%0A++,%22take_frequence%22:2,%22take_medical_number%22:1,%22take_medical_unit%22:%22%22,%22use_day%22:1,%22deliver_way%22:%22%22%7D%5D,%0A++%22diagnoses%22:%0A++%5B%7B%22diagnose_code%22:%22H33.001%22,%22diagnose_desc%22:%22%E5%AD%94%E6%BA%90%E6%80%A7%E8%A7%86%E7%BD%91%E8%86%9C%E8%84%B1%E7%A6%BB%22%7D,%5D,%0A++%22doctor_advice_no%22:%22%22,%22doctor_code%22:%221234%22,%22doctor_name%22:%22%E6%9D%A8%E8%BF%87%22,%22in_hosp_date%22:%2220141020%22,%22medical_dept_code%22:%22123456%22,%22medical_dept_name%22:%22%E6%80%A5%E8%AF%8A%E5%86%85%E7%A7%91%22,%0A++%22card_no%22:%22D49752662C%22,%22visit_no%22:%2200012147%22,%22visit_type%22:%222%22%7D&public_type=audit&temp=2015-11-17T03:02:46.205Z";

try {
URL url = new URL(add_url);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
// connection.setRequestProperty("Accept-Charset","GBK");
connection.setRequestProperty("Charset", "GBK");
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.connect();

JSONObject obj = new JSONObject();
query = add_url + query;
// String token = "pJokE9hWJ3QRy86zTOwnQkkkmazQfJFu9nOHwHmdinF4msD23OrZCnzlP3jBC3eSwmdYqY7lT4LTKoJlZmfTSg";
// obj.put("content",query);
//obj.put("auth_token", token);
//obj.put("public_type","audit");
System.out.println(query);
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(query);

out.flush();
out.close();

BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

String lines;

StringBuffer sbf = new StringBuffer();
while ((lines = reader.readLine()) != null) {

lines = new String(lines.getBytes("UTF-8"));
sbf.append(lines);
}
System.out.println(sbf);
reader.close();
// 断开连接
connection.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
getRemoteId();

}
}

时间: 2024-10-10 05:37:42

json发送hppt请求的相关文章

java 发送http请求

package cn.go4mi; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URL; import java.net.URLConnection; import java.util.List; import java.util.Map; public class H

Loadrunner接口测试-发送JSON格式的请求

昨天接到了一个测试接口的任务,接口的请求参数和返回结果均是JSON字符串,先是使用了函数web_submit_date,执行时报错,查询资料没找到原因,不知道是不是不支持JSON串,有兴趣的可以自己试下.然后尝试用web_custom_request函数,执行后返回的结果都正确,ok,就它了. web_custom_request("refund",                           //VuGen中树形视图中显示的名称         "Url=http:

通过在jquery中添加函数发送ajax请求来加载数据库数据,以json的格式发送到页面

通过在jquery中添加函数发送ajax请求来加载数据库数据,以json的格式发送到页面 从数据库中查询仓库信息,显示在下拉菜单中: 首先,引入js插件,这里使用jquery-1.8.3.js <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script> 当页面加载完成后,就应该发送ajax请求到数据库,

使用xutils发送POST请求,携带json和图片二进制文件数据获取服务器端返回json数据

接口文档: 换头像 接口 user/change_avatar 发送数据 HTTP Post body(一共2对KEY-VALUE): json={"uid":"1","sid":"0123456789ABCDEF0123456789ABCDEF","ver":"1","request":{}} file=图片二进制文件数据 返回数据 {"ret"

[SoapUI] 通过SoapUI发送POST请求,请求的body是JSON格式的数据

通过SoapUI发送POST请求,请求的body是JSON格式的数据: data={"currentDate":"2015-06-19","reset":true} 而且通过Fiddler抓取页面报文 Content-Type 是 application/x-www-form-urlencoded 一开始我将Content-Type = application/x-www-form-urlencoded 加到Header 里面. SoapUI里面

(九)springmvc之json的数据请求(客户端发送json数据到服务端)

index.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd&quo

Java发送POST请求,参数为JSON格式,并接收返回JSON数据

原文地址:https://blog.csdn.net/qq_26975307/article/details/82713725 /** * 发送post请求 * @param url 路径 * @param jsonObject 参数(json类型) * @param encoding 编码格式 * @return * @throws ParseException * @throws IOException */ public static String send(String url, JSO

Requests库发送post请求,传入接口参数后报JSON parse error

报错信息: {"timestamp":"2020-01-08T14:42:40.894+0000","status":400,"error":"Bad Request","message":"JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of VALUE_STRING tok

Android利用异步任务AsyncTask发送post请求获取json数据

AsyncTask,是android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作,并提供接口反馈当前异步执行的程度(可以通过接口实现UI进度更新),最后反馈执行的结果给UI主线程. 使用的优点: l  简单,快捷 l  过程可控 使用的缺点: l  在使用多个异步操作和并需要进行Ui变更时,就变得复杂起来. 2 )Handler异步实现的原理和适用的优缺点 AsyncTask介绍 Android的AsyncTask比Handler更轻量级一些,适用于简单的异步处理.