URL Requests basic tests file
This commit is contained in:
@@ -23,13 +23,16 @@ $file_get = file_get_contents('php://input') ?: '{"Error" => "file_get_contents
|
|||||||
|
|
||||||
$log->debug('SERVER', $log->prAr($_SERVER));
|
$log->debug('SERVER', $log->prAr($_SERVER));
|
||||||
$log->debug('HEADERS', $log->prAr($http_headers));
|
$log->debug('HEADERS', $log->prAr($http_headers));
|
||||||
|
$log->debug('GET', $log->prAr($_GET));
|
||||||
$log->debug('POST', $log->prAr($_POST));
|
$log->debug('POST', $log->prAr($_POST));
|
||||||
$log->debug('PHP-INPUT', $log->prAr($file_get));
|
$log->debug('PHP-INPUT', $log->prAr($file_get));
|
||||||
|
|
||||||
|
header("Content-Type: application/json; charset=UTF-8");
|
||||||
|
|
||||||
print Json::jsonConvertArrayTo([
|
print Json::jsonConvertArrayTo([
|
||||||
'HTTP_HEADERS' => $http_headers,
|
'HEADERS' => $http_headers,
|
||||||
"_GET" => $_GET,
|
"PARAMS" => $_GET,
|
||||||
"_POST" => Json::jsonConvertToArray($file_get),
|
"BODY" => Json::jsonConvertToArray($file_get),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$log->debug('[END]', '=========================================>');
|
$log->debug('[END]', '=========================================>');
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ $log = new CoreLibs\Logging\Logging([
|
|||||||
'log_per_date' => true,
|
'log_per_date' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$client = new Curl();
|
|
||||||
|
|
||||||
$PAGE_NAME = 'TEST CLASS: URL REQUESTS CURL';
|
$PAGE_NAME = 'TEST CLASS: URL REQUESTS CURL';
|
||||||
print "<!DOCTYPE html>";
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
||||||
@@ -35,87 +33,206 @@ print "<body>";
|
|||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||||
|
|
||||||
|
$client = new Curl();
|
||||||
|
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
$data = $client->requestGet(
|
$data = $client->get(
|
||||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||||
. '?other=get_a',
|
. '?other=get_a',
|
||||||
['test-header: ABC', 'request-type: _GET'],
|
[
|
||||||
['foo' => 'BAR']
|
'headers' => $client->prepareHeaders([
|
||||||
|
'test-header: ABC',
|
||||||
|
'info-request-type: _GET',
|
||||||
|
'Funk-pop' => 'Semlly god'
|
||||||
|
]),
|
||||||
|
'query' => ['foo' => 'BAR']
|
||||||
|
]
|
||||||
);
|
);
|
||||||
print "_GET RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
print "_GET RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
||||||
|
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
$data = $client->requestPost(
|
$data = $client->request(
|
||||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
'get',
|
||||||
. '?other=post_a',
|
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||||
['payload' => 'data post'],
|
. '?other=get_a',
|
||||||
[
|
|
||||||
'Content-Type: application/json',
|
|
||||||
'Accept: application/json',
|
|
||||||
'test-header: ABC',
|
|
||||||
'info-request-type: _POST'
|
|
||||||
],
|
|
||||||
['foo' => 'BAR post'],
|
|
||||||
);
|
);
|
||||||
print "_POST RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
print "_GET RESPONSE, nothing set: <pre>" . print_r($data, true) . "</pre>";
|
||||||
|
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
$data = $client->requestPut(
|
try {
|
||||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
$data = $client->request(
|
||||||
. '?other=put_a',
|
'get',
|
||||||
['payload' => 'data put'],
|
'soba54.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||||
|
. '?other=get_a',
|
||||||
|
);
|
||||||
|
print "_GET RESPONSE, nothing set, invalid URL: <pre>" . print_r($data, true) . "</pre>";
|
||||||
|
} catch (Exception $e) {
|
||||||
|
print "Exception: <pre>" . print_r($e, true) . "</pre><br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print "<hr>";
|
||||||
|
$data = $client->request(
|
||||||
|
"get",
|
||||||
|
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/'
|
||||||
|
. 'trunk/www/admin/UrlRequests.target.php'
|
||||||
|
. '?other=get_a',
|
||||||
[
|
[
|
||||||
'Content-Type: application/json',
|
"headers" => $client->prepareHeaders([
|
||||||
'Accept: application/json',
|
'test-header: ABC',
|
||||||
'test-header: ABC',
|
'info-request-type: _GET',
|
||||||
'info-request-type: _PUT'
|
'Funk-pop' => 'Semlly god'
|
||||||
|
]),
|
||||||
|
"query" => ['foo' => 'BAR'],
|
||||||
],
|
],
|
||||||
['foo' => 'BAR put'],
|
);
|
||||||
|
print "[request] _GET RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
||||||
|
|
||||||
|
print "<hr>";
|
||||||
|
$data = $client->post(
|
||||||
|
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||||
|
. '?other=post_a',
|
||||||
|
[
|
||||||
|
'body' => ['payload' => 'data post'],
|
||||||
|
'headers' => $client->prepareHeaders([
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Accept: application/json',
|
||||||
|
'test-header: ABC',
|
||||||
|
'info-request-type: _POST'
|
||||||
|
]),
|
||||||
|
'query' => ['foo' => 'BAR post'],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
print "_POST RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
||||||
|
print "<hr>";
|
||||||
|
$data = $client->request(
|
||||||
|
"post",
|
||||||
|
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||||
|
. '?other=post_a',
|
||||||
|
[
|
||||||
|
"body" => ['payload' => 'data post', 'request' => 'I am the request body'],
|
||||||
|
"headers" => $client->prepareHeaders([
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Accept: application/json',
|
||||||
|
'test-header: ABC',
|
||||||
|
'info-request-type: _POST'
|
||||||
|
]),
|
||||||
|
"query" => ['foo' => 'BAR post'],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
print "[request] _POST RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
||||||
|
|
||||||
|
print "<hr>";
|
||||||
|
$data = $client->put(
|
||||||
|
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||||
|
. '?other=put_a',
|
||||||
|
[
|
||||||
|
"body" => ['payload' => 'data put'],
|
||||||
|
"headers" => $client->prepareHeaders([
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Accept: application/json',
|
||||||
|
'test-header: ABC',
|
||||||
|
'info-request-type: _PUT'
|
||||||
|
]),
|
||||||
|
'query' => ['foo' => 'BAR put'],
|
||||||
|
]
|
||||||
);
|
);
|
||||||
print "_PUT RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
print "_PUT RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
||||||
|
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
$data = $client->requestPatch(
|
$data = $client->patch(
|
||||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||||
. '?other=patch_a',
|
. '?other=patch_a',
|
||||||
['payload' => 'data patch'],
|
|
||||||
[
|
[
|
||||||
'Content-Type: application/json',
|
"body" => ['payload' => 'data patch'],
|
||||||
'Accept: application/json',
|
"headers" => $client->prepareHeaders([
|
||||||
'test-header: ABC',
|
'Content-Type: application/json',
|
||||||
'info-request-type: _PATCH'
|
'Accept: application/json',
|
||||||
],
|
'test-header: ABC',
|
||||||
['foo' => 'BAR patch'],
|
'info-request-type: _PATCH'
|
||||||
|
]),
|
||||||
|
'query' => ['foo' => 'BAR patch'],
|
||||||
|
]
|
||||||
);
|
);
|
||||||
print "_PATCH RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
print "_PATCH RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
||||||
|
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
$data = $client->requestDelete(
|
$data = $client->delete(
|
||||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||||
. '?other=delete_no_body_a',
|
. '?other=delete_no_body_a',
|
||||||
null,
|
|
||||||
[
|
[
|
||||||
'Content-Type: application/json',
|
"body" => null,
|
||||||
'Accept: application/json',
|
"headers" => $client->prepareHeaders([
|
||||||
'test-header: ABC',
|
'Content-Type: application/json',
|
||||||
'info-request-type: _DELETE'
|
'Accept: application/json',
|
||||||
],
|
'test-header: ABC',
|
||||||
['foo' => 'BAR delete'],
|
'info-request-type: _DELETE'
|
||||||
|
]),
|
||||||
|
"query" => ['foo' => 'BAR delete'],
|
||||||
|
]
|
||||||
);
|
);
|
||||||
print "_DELETE RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
print "_DELETE RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
||||||
$data = $client->requestDelete(
|
|
||||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
print "<hr>";
|
||||||
|
$data = $client->delete(
|
||||||
|
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||||
. '?other=delete_body_a',
|
. '?other=delete_body_a',
|
||||||
['payload' => 'data delete'],
|
|
||||||
[
|
[
|
||||||
'Content-Type: application/json',
|
"body" => ['payload' => 'data delete'],
|
||||||
'Accept: application/json',
|
"headers" => $client->prepareHeaders([
|
||||||
'test-header: ABC',
|
'Content-Type: application/json',
|
||||||
'info-request-type: _DELETE'
|
'Accept: application/json',
|
||||||
],
|
'test-header: ABC',
|
||||||
['foo' => 'BAR delete'],
|
'info-request-type: _DELETE'
|
||||||
|
]),
|
||||||
|
"query" => ['foo' => 'BAR delete'],
|
||||||
|
]
|
||||||
);
|
);
|
||||||
print "_DELETE RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
print "_DELETE RESPONSE BODY: <pre>" . print_r($data, true) . "</pre>";
|
||||||
|
|
||||||
|
print "<hr>";
|
||||||
|
|
||||||
|
try {
|
||||||
|
$uc = new Curl([
|
||||||
|
"base_uri" => 'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/foo',
|
||||||
|
"headers" => [
|
||||||
|
'DEFAULT-master' => 'master-header',
|
||||||
|
'default-header' => 'uc-get',
|
||||||
|
'default-remove' => 'will be removed',
|
||||||
|
'default-remove-array' => ['a', 'b'],
|
||||||
|
'default-remove-array-part' => ['c', 'd'],
|
||||||
|
'default-remove-array-part-alt' => ['c', 'd', 'e'],
|
||||||
|
'default-overwrite' => 'will be overwritten',
|
||||||
|
'default-add' => 'will be added',
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
print "CONFIG: <pre>" . print_r($uc->getConfig(), true) . "</pre>";
|
||||||
|
$uc->removeHeaders(['default-remove' => '']);
|
||||||
|
$uc->removeHeaders(['default-remove-array' => ['a', 'b']]);
|
||||||
|
$uc->removeHeaders(['default-remove-array-part' => 'c']);
|
||||||
|
$uc->removeHeaders(['default-remove-array-part-alt' => ['c', 'd']]);
|
||||||
|
$uc->setHeaders(['default-new' => 'Something new']);
|
||||||
|
$uc->setHeaders(['default-overwrite' => 'Something Overwritten']);
|
||||||
|
$uc->setHeaders(['default-add' => 'Something Added'], true);
|
||||||
|
print "CONFIG: <pre>" . print_r($uc->getConfig(), true) . "</pre>";
|
||||||
|
$data = $uc->request(
|
||||||
|
'get',
|
||||||
|
'UrlRequests.target.php?other=get_a',
|
||||||
|
[
|
||||||
|
'headers' => [
|
||||||
|
'call-header' => 'call-get',
|
||||||
|
'default-header' => 'overwrite-uc-get',
|
||||||
|
'X-Foo' => ['bar', 'baz'],
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
print "[uc] _GET RESPONSE, nothing set: <pre>" . print_r($data, true) . "</pre>";
|
||||||
|
print "[uc] SENT URL: " . $uc->getUrlSent() . "<br>";
|
||||||
|
print "[uc] SENT URL PARSED: <pre>" . print_r($uc->getUrlParsedSent(), true) . "</pre>";
|
||||||
|
print "[uc] SENT HEADERS: <pre>" . print_r($uc->getHeadersSent(), true) . "</pre>";
|
||||||
|
} catch (Exception $e) {
|
||||||
|
print "Exception: <pre>" . print_r(json_decode($e->getMessage(), true), true) . "</pre><br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|||||||
Reference in New Issue
Block a user