保存进度!
This commit is contained in:
parent
9857451f05
commit
16c54998de
@ -2,7 +2,7 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-04-22 09:54:05
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-04-22 10:46:26
|
||||
* @LastEditTime: 2022-04-22 11:51:02
|
||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\httpUtil\HttpUtils.java
|
||||
* @Description: http相关的工具类。
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
@ -10,8 +10,10 @@
|
||||
|
||||
package com.cpic.xim.httpUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.net.URL;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -23,23 +25,45 @@ public class HttpUtils
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param url
|
||||
* @param headers
|
||||
* @param params
|
||||
* @param url 访问的链接字符串
|
||||
* @param headers 请求头部参数集合
|
||||
* @param params 请求体字符串
|
||||
*/
|
||||
public void postHttpRequest( String url, Map<String, String> headers,
|
||||
Map<String, String> params ) throws MalformedURLException
|
||||
public static void postHttpRequest( String url, HashMap<String, String> headers, String param )
|
||||
throws MalformedURLException
|
||||
{
|
||||
URL httpURL = null;
|
||||
HttpURLConnection conn = null;
|
||||
|
||||
try
|
||||
{
|
||||
// 获取connection
|
||||
httpURL = new URL( url );
|
||||
conn = (HttpURLConnection) httpURL.openConnection();
|
||||
|
||||
// 设置请求方式
|
||||
conn.setRequestMethod( "POST" );
|
||||
|
||||
// 设置请求头参数
|
||||
for ( HashMap.Entry<String, String> head : headers.entrySet())
|
||||
{
|
||||
String key = head.getKey();
|
||||
|
||||
conn.setRequestProperty( head.getKey(), head.getValue() );
|
||||
}
|
||||
|
||||
// 设置请求体
|
||||
|
||||
|
||||
}
|
||||
catch (MalformedURLException error)
|
||||
{
|
||||
|
||||
}
|
||||
catch (IOException error)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,20 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2022-04-22 10:53:49
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-04-22 11:41:52
|
||||
* @FilePath: \DisasterWarning\src\test\java\com\cpic\xim\wechat\officalAccount\sendMessageTest.java
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.cpic.xim.wechat.officalAccount;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import com.cpic.xim.httpUtil.*;
|
||||
import java.util.*;
|
||||
|
||||
public class sendMessageTest
|
||||
{
|
||||
@ -14,7 +26,7 @@ public class sendMessageTest
|
||||
{
|
||||
try
|
||||
{
|
||||
sendMessage.postNotifyMessageJSON( url, "警报", "警报标题", "警报内容!" );
|
||||
// sendMessage.postNotifyMessageJSON( url, "警报", "警报标题", "警报内容!" );
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
@ -25,8 +37,17 @@ public class sendMessageTest
|
||||
@Test
|
||||
public void postNotifyMessage()
|
||||
{
|
||||
HashMap<String, String> headers = new HashMap<String, String>();
|
||||
String param = "tplid : 57," + "groupid : 1," + "first : \"亲爱的#realname#,您好!\","
|
||||
+ "keyword1 : \"厦门发布暴雨红色预警\"," + "keyword1color : \"#ff0000\","
|
||||
+ "keyword2 : \"厦门市气象台**年**月**日发布暴雨红色预警信号\"";
|
||||
|
||||
headers.put( "accept", "*/*" );
|
||||
headers.put( "Connection", "Keep-Alive" );
|
||||
|
||||
try
|
||||
{
|
||||
HttpUtils.postHttpRequest( url, headers, param );
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user