प्रयास करें
मार्को का उत्तर को हटा दिया गया है, आपको निम्न वाक्यविन्यास का उपयोग करना होगा (जेसनलफंक की टिप्पणी के अनुसार):
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'http://www.example.com/user/create', [
'form_params' => [
'email' => '[email protected]',
'name' => 'Test user',
'password' => 'testpassword',
]
]);
पोस्ट फ़ाइलें पैरामीटर
// PUT
$client->put('http://www.example.com/user/4', [
'body' => [
'email' => '[email protected]',
'name' => 'Test user',
'password' => 'testpassword',
],
'timeout' => 5
]);
// DELETE
$client->delete('http://www.example.com/user');
Async पोस्ट डेटा
उपयोगी लंबे सर्वर कार्यों के लिए के साथ
$response = $client->request('POST', 'http://www.example.com/files/post', [
'multipart' => [
[
'name' => 'file_name',
'contents' => fopen('/path/to/file', 'r')
],
[
'name' => 'csv_header',
'contents' => 'First Name, Last Name, Username',
'filename' => 'csv_header.csv'
]
]
]);
बाकी क्रियाएं उपयोग के साथ अनुरोध।
$client = new \GuzzleHttp\Client();
$promise = $client->requestAsync('POST', 'http://www.example.com/user/create', [
'form_params' => [
'email' => '[email protected]',
'name' => 'Test user',
'password' => 'testpassword',
]
]);
$promise->then(
function (ResponseInterface $res) {
echo $res->getStatusCode() . "\n";
},
function (RequestException $e) {
echo $e->getMessage() . "\n";
echo $e->getRequest()->getMethod();
}
);
Documentation नई संभावनाओं के बारे में अधिक जानकारी है।
Passing in the "body" request option as an array to send a POST request has been deprecated. Please use the "form_params" request option to send a application/x-www-form-urlencoded request, or a the "multipart" request option to send a multipart/form-data request.
गलत:
$response = $client->post('http://example.com/api', [
'body' => [
'name' => 'Example name',
]
])
सही में guzzle V6.0 +
इस विधि अब 6.0 में मान्य नहीं है। 'बॉडी' के बजाय 'form_params' का उपयोग करें। – jasonlfunk
POST अनुरोध भेजने के लिए एक सरणी के रूप में "बॉडी" अनुरोध विकल्प में उत्तीर्ण किया गया है। एक आवेदन/एक्स-www-form-urlencoded अनुरोध भेजने के लिए "form_params" अनुरोध विकल्प का उपयोग करें, या एक मल्टीपार्ट/फॉर्म-डेटा अनुरोध भेजने के लिए "मल्टीपार्ट" अनुरोध विकल्प। –
@ जेरेमी क्विनटन, तो आपने उसमें से इंटीड का चयन किया है ... कृपया – Madhur