|
1 | | -# Requests |
| 1 | +# My Requests |
2 | 2 |
|
3 | | -Custom lại hàm Requests |
| 3 | +Library Interface Requests use cURL, File Get Contents, SOAP Requests |
| 4 | + |
| 5 | +Library use package: Curl, GuzzleHttp, Requests and nuSoap |
| 6 | + |
| 7 | +### Installation |
| 8 | + |
| 9 | +**Manual install** |
| 10 | + |
| 11 | +Step 1: Save library to your project |
| 12 | + |
| 13 | +```shell |
| 14 | +cd /your/to/path |
| 15 | +wget https://github.com/nguyenanhung/requests/archive/master.zip |
| 16 | +unzip master.zip |
| 17 | +``` |
| 18 | + |
| 19 | +Step 2: Init to Project |
| 20 | + |
| 21 | +```php |
| 22 | +<?php |
| 23 | +require '/your/to/path/MyRequests.php'; |
| 24 | +use \nguyenanhung\MyRequests\MyRequests; |
| 25 | + |
| 26 | +$requests = new MyRequests(); |
| 27 | + |
| 28 | +``` |
| 29 | + |
| 30 | +**Install with composer** |
| 31 | + |
| 32 | +Step 1: Install package |
| 33 | + |
| 34 | +```shell |
| 35 | +composer require nguyenanhung/requests |
| 36 | +``` |
| 37 | + |
| 38 | +Step 2: Init to Project |
| 39 | + |
| 40 | +```php |
| 41 | +<?php |
| 42 | +require '/your/to/path/vendor/autoload.php'; |
| 43 | +use \nguyenanhung\MyRequests\MyRequests; |
| 44 | +$requests = new MyRequests(); |
| 45 | +``` |
| 46 | + |
| 47 | +### **How to Use** |
| 48 | + |
| 49 | +**Get Version of Library** |
| 50 | + |
| 51 | +```php |
| 52 | +<?php |
| 53 | +require '/your/to/path/vendor/autoload.php'; |
| 54 | +use \nguyenanhung\MyRequests\MyRequests; |
| 55 | +$requests = new MyRequests(); |
| 56 | + |
| 57 | +echo $requests->getVersion(); // Print: 0.1.3.4 |
| 58 | +``` |
| 59 | + |
| 60 | +##### Send Request |
| 61 | + |
| 62 | +```php |
| 63 | +<?php |
| 64 | +require '/your/to/path/vendor/autoload.php'; |
| 65 | +use nguyenanhung\MyRequests\MyRequests; |
| 66 | + |
| 67 | +$debug = [ |
| 68 | + 'debugStatus' => TRUE, |
| 69 | + 'debugLoggerPath' => testLogPath() |
| 70 | +]; |
| 71 | +$url = 'https://httpbin.org/'; |
| 72 | +$data = [ |
| 73 | + 'date' => date('Y-m-d'), |
| 74 | + 'service' => 'ME', |
| 75 | + 'token' => 'empty' |
| 76 | +]; |
| 77 | +$method = 'GET'; |
| 78 | +$headers = []; |
| 79 | +$options = []; |
| 80 | +$request = new MyRequests(); |
| 81 | +$request->debugStatus = TRUE; |
| 82 | +$request->debugLoggerPath = '/your/to/path/save_log'; |
| 83 | +$request->__construct(); |
| 84 | +$request->setHeader($headers); |
| 85 | +$request->setOptions($options); |
| 86 | + |
| 87 | +echo $requests->getVersion(); // Print: 0.1.3.4 |
| 88 | + |
| 89 | +$pyRequest = $request->pyRequest($url, $data, $method); |
| 90 | +d($pyRequest); |
| 91 | + |
| 92 | +$guzzlePhpRequest = $request->guzzlePhpRequest($url, $data, $method); |
| 93 | +d($guzzlePhpRequest); |
| 94 | + |
| 95 | +$curlRequest = $request->curlRequest($url, $data, $method); |
| 96 | +d($curlRequest); |
| 97 | + |
| 98 | +$sendRequest = $request->sendRequest($url, $data, $method); |
| 99 | +d($sendRequest); |
| 100 | +``` |
| 101 | + |
| 102 | +##### Send Request with File Get Contents |
| 103 | + |
| 104 | +```php |
| 105 | +<?php |
| 106 | +require '/your/to/path/vendor/autoload.php'; |
| 107 | +use nguyenanhung\MyRequests\GetContents; |
| 108 | + |
| 109 | +// Test Data |
| 110 | +$url = 'https://httpbin.org/'; |
| 111 | +$data = [ |
| 112 | + 'date' => date('Y-m-d'), |
| 113 | + 'service' => 'ME', |
| 114 | + 'token' => 'empty' |
| 115 | +]; |
| 116 | +$method = 'GET'; |
| 117 | +// Let's Go |
| 118 | +$content = new GetContents(); |
| 119 | +$content->setURL($url); |
| 120 | +$content->setMethod($method); |
| 121 | +$content->setData($data); |
| 122 | +$content->sendRequest(); |
| 123 | + |
| 124 | +echo $content->getVersion(); // Print: 0.1.3.4 |
| 125 | + |
| 126 | +$response = $content->response(); |
| 127 | +$getContent = $content->getContent(); |
| 128 | +$getError = $content->getError(); |
| 129 | + |
| 130 | +d($response); |
| 131 | +d($getContent); |
| 132 | +d($getError); |
| 133 | +``` |
| 134 | + |
| 135 | +##### Send Request with SOAP Request |
| 136 | + |
| 137 | +```php |
| 138 | +<?php |
| 139 | +require '/your/to/path/vendor/autoload.php'; |
| 140 | +use nguyenanhung\MyRequests\SoapRequest; |
| 141 | + |
| 142 | +$soap = new SoapRequest(); |
| 143 | +$soap->debugStatus = true; |
| 144 | +$soap->debugLoggerPath = '/your/to/path/save_log'; |
| 145 | +$soap->__construct(); |
| 146 | +$soap->setEndpoint('url'); |
| 147 | +$soap->setCallFunction('function'); |
| 148 | +$soap->setData($data); |
| 149 | +$result = $soap->clientRequestWsdl(); |
| 150 | + |
| 151 | +echo $soap->getVersion(); // Print: 0.1.3.4 |
| 152 | +d($result); |
| 153 | +``` |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | +### Contact |
| 158 | + |
| 159 | +If any quetion & request, please contact following infomation |
| 160 | + |
| 161 | +| Name | Email | Skype | Facebook | |
| 162 | +| ----------- | -------------------- | ---------------- | ------------- | |
| 163 | +| Hung Nguyen | [email protected] | nguyenanhung5891 | @nguyenanhung | |
| 164 | + |
| 165 | +From Hanoi with Love <3 |
0 commit comments