暫未整理脫水
Java語法,Idea提示Usage of API Documented as @since 1.6+
解決方案:File->Project structure->module->source->language Level 改為1.6+版本Java語法,接1。改完后編譯失敗,提示javacTask:源發(fā)行版1.6,需要目標發(fā)行版1.6
解決方案:File->Settings->Build,Execution,Deployment->Complier->Java Complier->改為1.6+testNG執(zhí)行順序
用例中有2個case需要順序執(zhí)行。按照很多教程寫了preserve-order="true"發(fā)現(xiàn)并沒有用……為什么需要查證。解決方法是給第二順序執(zhí)行的case加上@Test(dependsOnMethods = {"testname"}解決。httpspost:
public static String HttpsPost(String url, Object obj){
HttpClient httpClient = new DefaultHttpClient();
X509TrustManager xtm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
try {
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null, new TrustManager[]{xtm}, null);
SSLSocketFactory socketFactory = new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, socketFactory));
HttpPost httpPost = new HttpPost(url);
StringEntity se = new StringEntity(JSON.toJSONString(obj), StandardCharsets.UTF_8);
httpPost.setEntity(se);
HttpResponse rep = httpClient.execute(httpPost);
HttpEntity entity = rep.getEntity();
if(null != entity){
String responseContent = EntityUtils.toString(entity, "UTF-8");
System.out.println(responseContent);
return responseContent;
}
return null;
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
e.printStackTrace();
return null;
}
}