Java直接读取classpath下的properties文件
private static final ResourceBundle bundle = java.util.ResourceBundle.getBundle("config");
bundle.getString("hessianurl");//读取属性数据
http测试:
import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.UUID; import org.jsoup.Jsoup; import org.jsoup.Connection.Method; import org.jsoup.Connection.Response; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import dao.pojo.his.Advice; import dao.pojo.his.Hisuserinfo; import hw.hlatform.secg.utils.DateUtils; import hw.hlatform.secg.utils.StringUtils; import hw.hlatform.secg.utils.viewmodel.ws.base.Common; import service.HisApiService; private static void determining() throws Exception{ Map<String, String> datas=new HashMap<String,String>();//组合参数 datas.put("uId", "65cc8129-c27d-41c5-b709-359850376cd5"); datas.put("confirmFlag", "1"); Response resp=Jsoup.connect("http://localhost:8089/his/determining").ignoreContentType(true).method(Method.POST).data(datas).execute();//直接发送,可以使用post方式也可以使用get方式 System.out.println(resp.body()); }
jsoup调用http服务是个很好的测试框架,其中可以设置调用http服务的超时时间,设置返回字符串的编码。更可贵的是可以服务端设置服务请求的方式,这样可以自动判别发送应该使用什么发送方式,服务器端用get就是get方式,用post就是post方式。
例如:
如果用下面的方法请求:http://www.baidu.com 如果设置connection.method(Method.POST)这种发送方式。则服务器回报403的错误。所以必须换成get方式则是正常。所以必须自适应服务器的发送方式。
/** * 调用http请求工具类 * @param url * @param params * @return * @throws Exception */ public static String buildRequest(String url,Map<String, String> params) throws Exception { Connection connection= Jsoup.connect(url); connection.ignoreContentType(true); connection.method(connection.request().method());//根据服务端的请求方式来判断是POST、GET connection.data(params); connection.timeout(1000*10);//设置10秒超时 Response response = connection.execute(); String strResult = new String(response.bodyAsBytes(), "UTF-8");//设置返回字符串编码 return strResult; }