Laravel 用口吻代替卷曲
我用Guzzle代替Curl来发出post请求,但当我试图用Guzzle替换一个正在工作的Curl示例时,它不起作用。我已经尝试过其他解决方案,但仍然给了我一个错误的凭证,这是没有意义的,因为它使用Curl工作,我还使用Postman测试凭证 我的工作职责是:Laravel 用口吻代替卷曲,laravel,curl,guzzle,guzzlehttp,Laravel,Curl,Guzzle,Guzzlehttp,我用Guzzle代替Curl来发出post请求,但当我试图用Guzzle替换一个正在工作的Curl示例时,它不起作用。我已经尝试过其他解决方案,但仍然给了我一个错误的凭证,这是没有意义的,因为它使用Curl工作,我还使用Postman测试凭证 我的工作职责是: $params = array( 'account' => 'username', 'licensekey' => '2669asdas',
$params = array(
'account' => 'username',
'licensekey' => '2669asdas',
'phoneNumber' => preg_replace('/\D/', '', $recipient),
'messageText' => $message,
'alfaSender' => 'somehting'
);
$ch = curl_init();
curl_setopt_array(
$ch,
array(
CURLOPT_URL => 'https://domain/API/send',
CURLOPT_HEADER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($params),
CURLOPT_RETURNTRANSFER => true
)
);
$response = curl_exec($ch);
curl_close($ch);
return $response;
我的不工作狂饮示例:
$client = new Client(); //GuzzleHttp\Client
$send_sms = $client->post('https://domainpt/API/send', [
'debug' => true,
'form_params' => [
'account' => 'username',
'licensekey' => 'passs',
'phoneNumber' => '96163233',
'messageText' => 'blbaaa',
'alfaSender' => 'Felo',
]
]);
错误:
Client error: `POST https://domain/API/send` resulted in a `401 Wrong Credentials` response: {"Result":"NOT OK", "ErrorCode":2, "ErrorDesc":"Wrong Credentials"}
尝试类似这样的操作:
$vars=array('state[]'=>array('Assigned','New'),'per_page'=>$perPage',page'=>$pageNumber)$query=http_build_query($vars,null,&')$string=preg_replace('/%5B(?[0-9]|[1-9][0-9]+)%5D=/','=',$query);//state[]=已分配&state[]=新$client=新客户端([按照说明初始化客户端…)$response=$client->request('POST',$uri,['query'=>$string])代码>我认为您的请求工作正常,它导致401,因为提供的凭据错误。您所需要的只是捕获该响应并返回到您的用户端。