Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cocktail-party-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cocktail-party
cocktail-party-server
Commits
4f1f0bdb
提交
4f1f0bdb
authored
5月 14, 2020
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
通用http发送方法增加参数 contentType 编码类型
上级
f3d0bf6c
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
22 行增加
和
2 行删除
+22
-2
Constants.java
ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java
+5
-0
HttpUtils.java
.../src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
+15
-1
AddressUtils.java
...src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java
+2
-1
没有找到文件。
ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java
浏览文件 @
4f1f0bdb
...
@@ -14,6 +14,11 @@ public class Constants
...
@@ -14,6 +14,11 @@ public class Constants
*/
*/
public
static
final
String
UTF8
=
"UTF-8"
;
public
static
final
String
UTF8
=
"UTF-8"
;
/**
* GBK 字符集
*/
public
static
final
String
GBK
=
"GBK"
;
/**
/**
* 通用成功标识
* 通用成功标识
*/
*/
...
...
ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
浏览文件 @
4f1f0bdb
...
@@ -18,6 +18,7 @@ import javax.net.ssl.TrustManager;
...
@@ -18,6 +18,7 @@ import javax.net.ssl.TrustManager;
import
javax.net.ssl.X509TrustManager
;
import
javax.net.ssl.X509TrustManager
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.ruoyi.common.constant.Constants
;
/**
/**
* 通用http发送方法
* 通用http发送方法
...
@@ -36,6 +37,19 @@ public class HttpUtils
...
@@ -36,6 +37,19 @@ public class HttpUtils
* @return 所代表远程资源的响应结果
* @return 所代表远程资源的响应结果
*/
*/
public
static
String
sendGet
(
String
url
,
String
param
)
public
static
String
sendGet
(
String
url
,
String
param
)
{
return
sendGet
(
url
,
param
,
Constants
.
UTF8
);
}
/**
* 向指定 URL 发送GET方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @param contentType 编码类型
* @return 所代表远程资源的响应结果
*/
public
static
String
sendGet
(
String
url
,
String
param
,
String
contentType
)
{
{
StringBuilder
result
=
new
StringBuilder
();
StringBuilder
result
=
new
StringBuilder
();
BufferedReader
in
=
null
;
BufferedReader
in
=
null
;
...
@@ -49,7 +63,7 @@ public class HttpUtils
...
@@ -49,7 +63,7 @@ public class HttpUtils
connection
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
connection
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
connection
.
setRequestProperty
(
"user-agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
connection
.
setRequestProperty
(
"user-agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
connection
.
connect
();
connection
.
connect
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
(),
"GBK"
));
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
(),
contentType
));
String
line
;
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
while
((
line
=
in
.
readLine
())
!=
null
)
{
{
...
...
ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java
浏览文件 @
4f1f0bdb
...
@@ -3,6 +3,7 @@ package com.ruoyi.common.utils.ip;
...
@@ -3,6 +3,7 @@ package com.ruoyi.common.utils.ip;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.http.HttpUtils
;
import
com.ruoyi.common.utils.http.HttpUtils
;
import
com.ruoyi.framework.config.RuoYiConfig
;
import
com.ruoyi.framework.config.RuoYiConfig
;
...
@@ -34,7 +35,7 @@ public class AddressUtils
...
@@ -34,7 +35,7 @@ public class AddressUtils
{
{
try
try
{
{
String
rspStr
=
HttpUtils
.
sendGet
(
IP_URL
,
"ip="
+
ip
+
"&json=true"
);
String
rspStr
=
HttpUtils
.
sendGet
(
IP_URL
,
"ip="
+
ip
+
"&json=true"
,
Constants
.
GBK
);
if
(
StringUtils
.
isEmpty
(
rspStr
))
if
(
StringUtils
.
isEmpty
(
rspStr
))
{
{
log
.
error
(
"获取地理位置异常 {}"
,
ip
);
log
.
error
(
"获取地理位置异常 {}"
,
ip
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论