更新
This commit is contained in:
@@ -11,6 +11,7 @@ import com.industry.common.annotation.RepeatSubmit;
|
||||
import com.industry.common.core.page.PageDomain;
|
||||
import com.industry.common.core.redis.RedisCache;
|
||||
|
||||
import com.industry.common.utils.http.HttpUtils;
|
||||
import com.industry.work.domain.IndustryMaterial;
|
||||
import com.industry.work.domain.IndustryStep;
|
||||
import com.industry.work.domain.dto.IndustryMaterialDto;
|
||||
@@ -34,6 +35,7 @@ import com.industry.common.core.domain.AjaxResult;
|
||||
import com.industry.common.enums.BusinessType;
|
||||
import com.industry.common.utils.poi.ExcelUtil;
|
||||
import com.industry.common.core.page.TableDataInfo;
|
||||
import sun.net.www.http.HttpClient;
|
||||
|
||||
/**
|
||||
* 钽靶主类Controller
|
||||
@@ -213,6 +215,8 @@ public class IndustryMaterialController extends BaseController
|
||||
return error();
|
||||
}
|
||||
industryMaterialService.updateIndustryMaterial(industryMaterial);
|
||||
// TODO 加入ip地址请求
|
||||
// HttpUtils.dataPost()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package com.industry.common.utils.http;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.*;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
@@ -17,6 +13,9 @@ import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.industry.common.constant.Constants;
|
||||
@@ -189,6 +188,85 @@ public class HttpUtils
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定 URL 发送POST方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param obj 请求参数,请求参数应该是JSONObject 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String dataPost(String url, JSONObject obj)
|
||||
{
|
||||
OutputStreamWriter out = null;
|
||||
BufferedReader in = null;
|
||||
StringBuilder result = new StringBuilder();
|
||||
try
|
||||
{
|
||||
URL realUrl = new URL(url);
|
||||
URLConnection conn = realUrl.openConnection();
|
||||
conn.setRequestProperty("accept", "*/*");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("connection", "Keep-Alive");
|
||||
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||
conn.setRequestProperty("Accept-Charset", "utf-8");
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
String json = obj.toJSONString();
|
||||
|
||||
//发送post请求
|
||||
out = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8);
|
||||
out.write(json);
|
||||
out.flush();
|
||||
|
||||
// 定义BufferedReader输入流来读取URL的响应
|
||||
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null)
|
||||
{
|
||||
result.append(line);
|
||||
}
|
||||
log.info("recv - {}", result);
|
||||
}
|
||||
catch (ConnectException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",obj=" + obj, e);
|
||||
}
|
||||
catch (SocketTimeoutException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",obj=" + obj, e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendPost IOException, url=" + url + ",obj=" + obj, e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",obj=" + obj, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (out != null)
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
if (in != null)
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
log.error("调用in.close Exception, url=" + url + ",obj=" + obj, ex);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static String sendSSLPost(String url, String param)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user