I made a API Request with Authentication in php and Code is working and everything good
this is Code PHP:
error_reporting(E_ALL);
ini_set( 'display_errors','1');
$url = "http://192.168.254.124:80/osc/commands/execute";
$username = "THETAYN10113693";
$password = "10113693";
$Body = json_encode( array( 'name' => 'camera.takePicture' ));
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_VERBOSE => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false, // for https
CURLOPT_USERPWD => $username . ":" . $password,
CURLOPT_HTTPAUTH => CURLAUTH_DIGEST,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array('Content-Type:application/json'),
CURLOPT_POSTFIELDS => $Body
);
$ch = curl_init();
curl_setopt_array( $ch, $options );
$raw_response = curl_exec( $ch );
echo "raw response: " . $raw_response;
but problem is in response I got 2 messages first is error :
raw response: HTTP/1.1 401 Unauthorized Connection
and Second : code is working good :
text/html HTTP/1.1 200 OK Connection: Keep-Alive X-Content-Type-Options: nosniff Content-Length: 92 Content-Type: application/json; charset=utf-8 {"id":"885","name":"camera.takePicture","progress":{"completion":0.00},"state":"inProgress"}
Full Response:
raw response: HTTP/1.1 401 Unauthorized Connection: Keep-Alive WWW-Authenticate: Digest realm="RICOH THETA Z1", qop="auth", nonce="O5kAeduJSn69042jpxNmGA==", algorithm=MD5 Content-Length: 0 Content-Type: text/html HTTP/1.1 200 OK Connection: Keep-Alive X-Content-Type-Options: nosniff Content-Length: 92 Content-Type: application/json; charset=utf-8 {"id":"885","name":"camera.takePicture","progress":{"completion":0.00},"state":"inProgress"}
I don't want the first message ((error message)) to appear ,what I should doing?
thanks so much
Aucun commentaire:
Enregistrer un commentaire