java post request code
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java post request code相关的知识,希望对你有一定的参考价值。
/* * Project Name:Tconfig * File Name:Main.java * Package Name:packages * Date:2017-3-21下午6:03:01 * Copyright (c) 2017, [email protected] 陈飞 Rights Reserved. * */ package packages; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import common.Common; import data.S1; /* * ClassName:Main * Function: ADD FUNCTION. * Reason: ADD REASON. * Date: 2017-3-21 下午6:03:01 * @author guosen * @version * @since JDK 1.6 */ public class Main { public static void main(String[] args) throws InterruptedException,IOException { //接口地址 String urlStr = "http://172.24.175.81:8081/WebServices/Seal.ashx"; URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("POST"); // POST方法 conn.connect(); // 写入的POST数据 OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream(),"UTF-8"); osw.write(S1.jsonString); osw.flush(); osw.close(); // 读取响应数据 BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String s; while ((s = in.readLine()) != null) System.out.println(s); /* * while(true) { System.out.println(new Common().getsecnum()); * Thread.sleep(1000); } */ } }
以上是关于java post request code的主要内容,如果未能解决你的问题,请参考以下文章