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('HEADERS', $log->prAr($http_headers));
|
||||
$log->debug('GET', $log->prAr($_GET));
|
||||
$log->debug('POST', $log->prAr($_POST));
|
||||
$log->debug('PHP-INPUT', $log->prAr($file_get));
|
||||
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
|
||||
print Json::jsonConvertArrayTo([
|
||||
'HTTP_HEADERS' => $http_headers,
|
||||
"_GET" => $_GET,
|
||||
"_POST" => Json::jsonConvertToArray($file_get),
|
||||
'HEADERS' => $http_headers,
|
||||
"PARAMS" => $_GET,
|
||||
"BODY" => Json::jsonConvertToArray($file_get),
|
||||
]);
|
||||
|
||||
$log->debug('[END]', '=========================================>');
|
||||
|
||||
@@ -26,8 +26,6 @@ $log = new CoreLibs\Logging\Logging([
|
||||
'log_per_date' => true,
|
||||
]);
|
||||
|
||||
$client = new Curl();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: URL REQUESTS CURL';
|
||||
print "<!DOCTYPE html>";
|
||||
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><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$client = new Curl();
|
||||
|
||||
print "<hr>";
|
||||
$data = $client->requestGet(
|
||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
||||
. '?other=get_a',
|
||||
['test-header: ABC', 'request-type: _GET'],
|
||||
['foo' => 'BAR']
|
||||
$data = $client->get(
|
||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||
. '?other=get_a',
|
||||
[
|
||||
'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 "<hr>";
|
||||
$data = $client->requestPost(
|
||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
||||
. '?other=post_a',
|
||||
['payload' => 'data post'],
|
||||
[
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
'test-header: ABC',
|
||||
'info-request-type: _POST'
|
||||
],
|
||||
['foo' => 'BAR post'],
|
||||
$data = $client->request(
|
||||
'get',
|
||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||
. '?other=get_a',
|
||||
);
|
||||
print "_POST RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
||||
print "_GET RESPONSE, nothing set: <pre>" . print_r($data, true) . "</pre>";
|
||||
|
||||
print "<hr>";
|
||||
$data = $client->requestPut(
|
||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
||||
. '?other=put_a',
|
||||
['payload' => 'data put'],
|
||||
try {
|
||||
$data = $client->request(
|
||||
'get',
|
||||
'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',
|
||||
'Accept: application/json',
|
||||
'test-header: ABC',
|
||||
'info-request-type: _PUT'
|
||||
"headers" => $client->prepareHeaders([
|
||||
'test-header: ABC',
|
||||
'info-request-type: _GET',
|
||||
'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 "<hr>";
|
||||
$data = $client->requestPatch(
|
||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
||||
$data = $client->patch(
|
||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||
. '?other=patch_a',
|
||||
['payload' => 'data patch'],
|
||||
[
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
'test-header: ABC',
|
||||
'info-request-type: _PATCH'
|
||||
],
|
||||
['foo' => 'BAR patch'],
|
||||
"body" => ['payload' => 'data patch'],
|
||||
"headers" => $client->prepareHeaders([
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
'test-header: ABC',
|
||||
'info-request-type: _PATCH'
|
||||
]),
|
||||
'query' => ['foo' => 'BAR patch'],
|
||||
]
|
||||
);
|
||||
print "_PATCH RESPONSE: <pre>" . print_r($data, true) . "</pre>";
|
||||
|
||||
print "<hr>";
|
||||
$data = $client->requestDelete(
|
||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlReqeusts.target.php'
|
||||
$data = $client->delete(
|
||||
'https://soba.egplusww.jp/developers/clemens/core_data/php_libraries/trunk/www/admin/UrlRequests.target.php'
|
||||
. '?other=delete_no_body_a',
|
||||
null,
|
||||
[
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
'test-header: ABC',
|
||||
'info-request-type: _DELETE'
|
||||
],
|
||||
['foo' => 'BAR delete'],
|
||||
"body" => null,
|
||||
"headers" => $client->prepareHeaders([
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
'test-header: ABC',
|
||||
'info-request-type: _DELETE'
|
||||
]),
|
||||
"query" => ['foo' => 'BAR delete'],
|
||||
]
|
||||
);
|
||||
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',
|
||||
['payload' => 'data delete'],
|
||||
[
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
'test-header: ABC',
|
||||
'info-request-type: _DELETE'
|
||||
],
|
||||
['foo' => 'BAR delete'],
|
||||
"body" => ['payload' => 'data delete'],
|
||||
"headers" => $client->prepareHeaders([
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
'test-header: ABC',
|
||||
'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>";
|
||||
|
||||
Reference in New Issue
Block a user