Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JSH ERP
Commits
08104760
"src/main/webapp/upload/article/1/1462527020936.jpg" did not exist on "6da03905cce286fd91150efb3cda00916da494ec"
Commit
08104760
authored
Mar 31, 2019
by
季圣华
Browse files
解决bug
parent
d73781d8
Changes
22
Show whitespace changes
Inline
Side-by-side
src/main/java/com/jsh/erp/utils/HttpClient.java
0 → 100644
View file @
08104760
package
com.jsh.erp.utils
;
import
com.alibaba.fastjson.JSONObject
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.entity.EntityBuilder
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.ContentType
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
static
org
.
apache
.
http
.
HttpStatus
.
SC_OK
;
public
final
class
HttpClient
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpClient
.
class
);
private
static
final
RequestConfig
REQUEST_CONFIG
=
RequestConfig
.
custom
().
setSocketTimeout
(
15000
).
setConnectTimeout
(
10000
).
build
();
/**
* 采用Get方式发送请求,获取响应数据
* @param url
* @return
*/
public
static
JSONObject
httpGet
(
String
url
){
CloseableHttpClient
client
=
HttpClientBuilder
.
create
().
build
();
HttpGet
httpGet
=
new
HttpGet
(
url
);
httpGet
.
setConfig
(
REQUEST_CONFIG
);
try
{
CloseableHttpResponse
chr
=
client
.
execute
(
httpGet
);
int
statusCode
=
chr
.
getStatusLine
().
getStatusCode
();
if
(
SC_OK
!=
statusCode
)
{
throw
new
RuntimeException
(
String
.
format
(
"%s查询出现异常"
,
url
));
}
String
entity
=
EntityUtils
.
toString
(
chr
.
getEntity
(),
StandardCharsets
.
UTF_8
);
JSONObject
object
=
JSONObject
.
parseObject
(
entity
);
return
object
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
String
.
format
(
"%s"
,
url
)
+
"查询出现异常"
);
}
finally
{
try
{
client
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
/**
* 采用Post方式发送请求,获取响应数据
*
* @param url url地址
* @param param 参数值键值对的字符串
* @return
*/
public
static
String
httpPost
(
String
url
,
String
param
)
{
CloseableHttpClient
client
=
HttpClientBuilder
.
create
().
build
();
try
{
HttpPost
post
=
new
HttpPost
(
url
);
EntityBuilder
builder
=
EntityBuilder
.
create
();
builder
.
setContentType
(
ContentType
.
APPLICATION_JSON
);
builder
.
setText
(
param
);
post
.
setEntity
(
builder
.
build
());
CloseableHttpResponse
response
=
client
.
execute
(
post
);
int
statusCode
=
response
.
getStatusLine
().
getStatusCode
();
HttpEntity
entity
=
response
.
getEntity
();
String
data
=
EntityUtils
.
toString
(
entity
,
StandardCharsets
.
UTF_8
);
logger
.
info
(
"状态:"
+
statusCode
+
"数据:"
+
data
);
return
data
;
}
catch
(
Exception
e
){
throw
new
RuntimeException
(
e
.
getMessage
());
}
finally
{
try
{
client
.
close
();
}
catch
(
Exception
ex
){
}
}
}
}
\ No newline at end of file
src/main/resources/application.properties
View file @
08104760
...
...
@@ -27,7 +27,10 @@ pagehelper.supportMethodsArguments=false
#open开启 close关闭
mybatis-plus.status
=
close
mybatis-plus.mapper-locations
=
classpath:./mapper_xml/*.xml
#获取管理系统信息
manage.ip
=
127.0.0.1
manage.port
=
8090
manage.roleId
=
10
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
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