验证中...
语言: Java
分类: 常用工具包
最后更新于 2018-06-15 16:06
gistfile1.txt
原始数据 复制代码
package com.c;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class RestUtil {
public String load(String url,String query) throws Exception
{
URL restURL = new URL(url);
/*
* 此处的urlConnection对象实际上是根据URL的请求协议(此处是http)生成的URLConnection类 的子类HttpURLConnection
*/
HttpURLConnection conn = (HttpURLConnection) restURL.openConnection();
//请求方式
conn.setRequestMethod("POST");
//设置是否从httpUrlConnection读入,默认情况下是true; httpUrlConnection.setDoInput(true);
conn.setDoOutput(true);
//allowUserInteraction 如果为 true,则在允许用户交互(例如弹出一个验证对话框)的上下文中对此 URL 进行检查。
conn.setAllowUserInteraction(false);
PrintStream ps = new PrintStream(conn.getOutputStream());
ps.print(query);
ps.close();
BufferedReader bReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line,resultStr="";
while(null != (line=bReader.readLine()))
{
resultStr +=line;
}
System.out.println("3412412---"+resultStr);
bReader.close();
return resultStr;
}
public static void main(String []args) {try {
RestUtil restUtil = new RestUtil();
String resultString = restUtil.load(
"http://192.168.10.89:8080/eoffice-restful/resources/sys/oaholiday",
"floor=first&year=2017&month=9&isLeader=N");
} catch (Exception e) {
// TODO: handle exception
System.out.print(e.getMessage());
}
}
}

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助

12_float_left_people 12_float_left_close