Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-rpc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
without authentication
meibuyu-rpc
Commits
9f9dd18e
Commit
9f9dd18e
authored
Sep 07, 2020
by
王源
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
e0eac877
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
16 deletions
+15
-16
HttpRequestJson.php
src/Tools/HttpRequestJson.php
+15
-16
No files found.
src/Tools/HttpRequestJson.php
View file @
9f9dd18e
...
@@ -19,13 +19,14 @@ namespace Meibuyu\Micro\Tools;
...
@@ -19,13 +19,14 @@ namespace Meibuyu\Micro\Tools;
class
HttpRequestJson
class
HttpRequestJson
{
{
protected
static
function
prepareRequest
(
&
$headers
=
[],
&
$data
=
[])
protected
static
function
prepareRequest
(
$headers
,
$data
=
[])
{
{
$data
=
json_encode
(
$data
);
$data
=
json_encode
(
$data
);
if
(
!
$data
)
{
if
(
!
empty
(
$data
)
)
{
$headers
[
'Content-type'
]
=
'application/json'
;
$headers
[
'Content-type'
]
=
'application/json'
;
$headers
[
'Content-Length'
]
=
strlen
(
$data
);
$headers
[
'Content-Length'
]
=
strlen
(
$data
);
}
}
return
[
$headers
,
$data
];
}
}
// /**
// /**
...
@@ -43,27 +44,27 @@ class HttpRequestJson
...
@@ -43,27 +44,27 @@ class HttpRequestJson
// /**
// /**
// * post请求
// * post请求
// * @param $url
// * @param $url
// * @param $data
Array
// * @param $data
// * @param array $httpHeaders
// * @param array $httpHeaders
// * @return ResponseInterface
// * @return ResponseInterface
// */
// */
// public static function post($url, $data
Array
, $httpHeaders = [])
// public static function post($url, $data, $httpHeaders = [])
// {
// {
// $client = new Client(['timeout' => 30]);
// $client = new Client(['timeout' => 30]);
// return $client->post($url, ['headers' => $httpHeaders, 'json' => $data
Array
]);
// return $client->post($url, ['headers' => $httpHeaders, 'json' => $data]);
// }
// }
//
//
// /**
// /**
// * put请求
// * put请求
// * @param $url
// * @param $url
// * @param $data
Array
// * @param $data
// * @param array $httpHeaders
// * @param array $httpHeaders
// * @return ResponseInterface
// * @return ResponseInterface
// */
// */
// public static function put($url, $data
Array
, $httpHeaders = [])
// public static function put($url, $data, $httpHeaders = [])
// {
// {
// $client = new Client(['timeout' => 30]);
// $client = new Client(['timeout' => 30]);
// return $client->put($url, ['headers' => $httpHeaders, 'json' => $data
Array
]);
// return $client->put($url, ['headers' => $httpHeaders, 'json' => $data]);
// }
// }
//
//
// /**
// /**
...
@@ -86,21 +87,20 @@ class HttpRequestJson
...
@@ -86,21 +87,20 @@ class HttpRequestJson
*/
*/
public
static
function
get
(
$url
,
$headers
=
[])
public
static
function
get
(
$url
,
$headers
=
[])
{
{
self
::
prepareRequest
(
$headers
);
return
CurlRequest
::
get
(
$url
,
$headers
);
return
CurlRequest
::
get
(
$url
,
$headers
);
}
}
/**
/**
* post请求
* post请求
* @param $url
* @param $url
* @param $data
Array
* @param $data
* @param array $headers
* @param array $headers
* @return array
* @return array
*/
*/
public
static
function
post
(
$url
,
$data
Array
,
$headers
=
[])
public
static
function
post
(
$url
,
$data
,
$headers
=
[])
{
{
self
::
prepareRequest
(
$headers
,
$dataArray
);
[
$headers
,
$data
]
=
self
::
prepareRequest
(
$headers
,
$data
);
return
CurlRequest
::
post
(
$url
,
$data
Array
,
$headers
);
return
CurlRequest
::
post
(
$url
,
$data
,
$headers
);
}
}
/**
/**
...
@@ -112,8 +112,8 @@ class HttpRequestJson
...
@@ -112,8 +112,8 @@ class HttpRequestJson
*/
*/
public
static
function
put
(
$url
,
$data
,
$headers
=
[])
public
static
function
put
(
$url
,
$data
,
$headers
=
[])
{
{
self
::
prepareRequest
(
$headers
,
$dataArray
);
[
$headers
,
$data
]
=
self
::
prepareRequest
(
$headers
,
$data
);
return
CurlRequest
::
put
(
$url
,
$data
Array
,
$headers
);
return
CurlRequest
::
put
(
$url
,
$data
,
$headers
);
}
}
/**
/**
...
@@ -124,7 +124,6 @@ class HttpRequestJson
...
@@ -124,7 +124,6 @@ class HttpRequestJson
*/
*/
public
static
function
delete
(
$url
,
$headers
=
[])
public
static
function
delete
(
$url
,
$headers
=
[])
{
{
self
::
prepareRequest
(
$headers
);
return
CurlRequest
::
delete
(
$url
,
$headers
);
return
CurlRequest
::
delete
(
$url
,
$headers
);
}
}
...
...
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