how to use basic authorization in php curl

how to use basic authorization in php curl?

Try Following Code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$username='ABC';
$password='XYZ';
$URL='<URL>';
$curlPost = 'username='.urlencode($username).'&
password='.urlencode($password).'&
sendto='.urlencode($sendto).'&
message='.urlencode($message).'';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
//post 方式提交
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
//end
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$result=curl_exec ($ch);
curl_close ($ch);

 

坚持原创技术分享,您的支持将鼓励我继续创作!