码迷,mamicode.com
首页 > Web开发 > 详细

json发送hppt请求

时间:2015-11-17 16:32:53      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

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();

}
}

json发送hppt请求

标签:

原文地址:http://www.cnblogs.com/zszitman/p/4971951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!