Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
徐少华
midjourney-proxy
Commits
8a806e9c
Commit
8a806e9c
authored
Sep 29, 2018
by
songxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
长短链接转换改为POST请求
parent
dcaceac2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
UrlUtils.java
...ain/java/com/pcloud/common/utils/httpclient/UrlUtils.java
+20
-10
No files found.
pcloud-common/src/main/java/com/pcloud/common/utils/httpclient/UrlUtils.java
View file @
8a806e9c
package
com
.
pcloud
.
common
.
utils
.
httpclient
;
package
com
.
pcloud
.
common
.
utils
.
httpclient
;
import
java.io.IOException
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.pcloud.common.utils.rsa.MD5
;
import
com.pcloud.common.utils.string.StringUtil
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.fastjson.JSONArray
;
import
java.io.IOException
;
import
com.alibaba.fastjson.JSONObject
;
import
java.nio.charset.Charset
;
import
com.pcloud.common.utils.rsa.MD5
;
import
com.pcloud.common.utils.string.StringUtil
;
/**
/**
* @author:songx
* @author:songx
...
@@ -35,7 +37,7 @@ public class UrlUtils {
...
@@ -35,7 +37,7 @@ public class UrlUtils {
/**
/**
* 请求地址(OWN)
* 请求地址(OWN)
*/
*/
private
static
final
String
REQUEST_URL2
=
"https://rays.5rs.me/convert/v1.0/url/shorten
Url?originUrl=
"
;
private
static
final
String
REQUEST_URL2
=
"https://rays.5rs.me/convert/v1.0/url/shorten"
;
/**
/**
* 获取短链接(新浪)
* 获取短链接(新浪)
...
@@ -57,7 +59,7 @@ public class UrlUtils {
...
@@ -57,7 +59,7 @@ public class UrlUtils {
/**
/**
* 发送请求(新浪)
* 发送请求(新浪)
*
*
* @param
requestU
rl
* @param
long_u
rl
* @return
* @return
*/
*/
private
static
String
callHttp
(
String
long_url
)
{
private
static
String
callHttp
(
String
long_url
)
{
...
@@ -107,10 +109,18 @@ public class UrlUtils {
...
@@ -107,10 +109,18 @@ public class UrlUtils {
return
null
;
return
null
;
}
}
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
Http
Get
httpGet
=
new
HttpGet
(
REQUEST_URL2
+
long_url
);
Http
Post
httpPost
=
new
HttpPost
(
REQUEST_URL2
);
String
resContent
=
null
;
String
resContent
=
null
;
try
{
try
{
CloseableHttpResponse
response
=
httpclient
.
execute
(
httpGet
);
//设置参数到请求对象中
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"originUrl"
,
long_url
);
StringEntity
stringEntity
=
new
StringEntity
(
jsonObject
.
toJSONString
(),
Charset
.
forName
(
"UTF-8"
));
httpPost
.
setEntity
(
stringEntity
);
//设置header信息
//指定报文头【Content-type】、【User-Agent】
httpPost
.
setHeader
(
"Content-type"
,
"application/json;charset=UTF-8"
);
CloseableHttpResponse
response
=
httpclient
.
execute
(
httpPost
);
// 获取响应实体
// 获取响应实体
HttpEntity
entity
=
response
.
getEntity
();
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
if
(
entity
!=
null
)
{
...
...
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