اینجوری اوکی شد
میزارم برای بقیه دوستان
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'http://test.com:100/Api/Request/GetAgentGroup' , [
\GuzzleHttp\RequestOptions::JSON => ['ApiKey' => 'test']
]);
$response->getStatusCode(); # 200
$response->getHeaderLine('content-type');
$agents = $response->getBody();
درود
به شسکل زیر میتونید یه درخواست پست بهمراه اطلاعات بدنه (body) ارسال کنید:
درنسخه های زیر ۶ پکیج Guzzle:
$client = new \GuzzleHttp\Client();
$client->post(
'http://www.example.com/user/create',
array(
'body' => array(
'email' => 'test@gmail.com',
'password' => 'testpassword'
)
)
);
درنسخه ۶ به بعد پکیج Guzzle:
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'http://www.example.com/user/create', [
'form_params' => [
'email' => 'test@gmail.com',
'password' => 'testpassword',
]
]);بصورت json بخوام باشه چی؟
شاید پاسخ شما همینجا باشد
Class 'App\Http\Controllers\dashboard\GuzzleHttp\RequestOptions' not found
import هم نمیشه
از نسخه ۶
خوب من چجوری میتونم تو کنترلر هام ازش استفاده کنم ؟
الان این ارورو میده
Class 'Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory' not found
$client = new \GuzzleHttp\Client();
$r = $client->post('http://test.com:100/Api/Request/GetAgentGroup', [
\GuzzleHttp\RequestOptions::JSON => ['ApiKey' => 'dfgdgdfgdfgdgderttertert']
]);
return $r;
به شکل زیر هم امتحان کنید:
$client->request('POST', '/url', [
'json' => ['ApiKey' => 'foobar']
]);
در مستندات این ابزار هم لیست کاملی از نوع درخواستها هست. لینک زیر:
http://docs.guzzlephp.org/en/stable/request-options.html#json
سلام از پکیج زیر استفاده کنید
https://github.com/shetabit/extractor
دستورات به صورت زیر میشه:
// at the top
use Shetabit\Extractor\Classes\Request;
//...
// create new request
$request = new Request();
// set api's url and method
$request->setUri('http://yoursite.com/api/v1/endpoint')
->setMethod('get');
// run the request and get data
$response = $requet->fetch();
var_dump($response); // show given response
به همین راحتی :)
حالا اگه میخواید اطلاعاتی ارسال کنید به صورت زیر عمل کنید:
// at the top
use Shetabit\Extractor\Classes\Request;
//...
// create new request
$request = new Request();
// set api's url and method
$request->setUri('http://yoursite.com/api/v1/endpoint')
->addFormParam('email','testmail@gmail.com')
->addFormparam('password','123456789')
->setMethod('get');
// run the request and get data
$response = $requet->fetch();
var_dump($response); // show given responseسعی کردم نصب کنم
با نسخه php من نمیخونه
Package shetabit/extractor at version has a PHP requirement incompatible with your PHP version (7.1.23)