Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finance-manage
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
finance-oa
finance-manage
Commits
4f1f0bdb
Commit
4f1f0bdb
authored
May 14, 2020
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
通用http发送方法增加参数 contentType 编码类型
parent
f3d0bf6c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
3 deletions
+23
-3
ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java
ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java
+6
-1
ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
.../src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
+15
-1
ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java
...src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java
+2
-1
No files found.
ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java
View file @
4f1f0bdb
...
...
@@ -13,7 +13,12 @@ public class Constants
* 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
View file @
4f1f0bdb
...
...
@@ -18,6 +18,7 @@ import javax.net.ssl.TrustManager;
import
javax.net.ssl.X509TrustManager
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.ruoyi.common.constant.Constants
;
/**
* 通用http发送方法
...
...
@@ -36,6 +37,19 @@ public class HttpUtils
* @return 所代表远程资源的响应结果
*/
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
();
BufferedReader
in
=
null
;
...
...
@@ -49,7 +63,7 @@ public class HttpUtils
connection
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
connection
.
setRequestProperty
(
"user-agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
connection
.
connect
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
(),
"GBK"
));
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
(),
contentType
));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
...
...
ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java
View file @
4f1f0bdb
...
...
@@ -3,6 +3,7 @@ package com.ruoyi.common.utils.ip;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.fastjson.JSONObject
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.http.HttpUtils
;
import
com.ruoyi.framework.config.RuoYiConfig
;
...
...
@@ -34,7 +35,7 @@ public class AddressUtils
{
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
))
{
log
.
error
(
"获取地理位置异常 {}"
,
ip
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment