我想用我的laravel應用程序發送短信。我有infobip測試帳戶,並使用該信息來短信發短信,但收到此錯誤:infraip單人短信服務在laravel中使用guzzle
ClientException in RequestException.php line 111:
Client error: `POST https://api.infobip.com/sms/1/text/single` resulted in a `401 Unauthorized` response:
{"requestError":{"serviceException": {"messageId":"UNAUTHORIZED","text":"Invalid login details"}}}
CODE:
$data= '{
"from":"InfoSMS",
"to":"923227124444",
"text":"Test SMS."
}';
$userstring = 'myuserame:password';
$id =base64_encode ('myuserame:password');
echo 'Basic '.$id;
$client = new \GuzzleHttp\Client();
$request = $client->post('https://api.infobip.com/sms/1/text/single',array(
'content-type' => 'application/json'
),['auth' => ['myusername', 'password']]);
$request->setHeaders(array(
'accept' => 'application/json',
'authorization' => 'Basic '.$id,
'content-type' => 'application/json'
));
$request->setBody($data); #set body!
$response = $request->send();
echo $res->getStatusCode(); // 200
echo $res->getBody();
return $response;
的用戶名和pssword是正確的,因爲我試圖發送直接短信該網站及其在那裏工作。
任何人都可以幫我,我做錯了什麼?
謝謝!
我在這裏得到了請求錯誤,但我累了用捲曲來解決它。在這裏放置代碼。 –