php - Duplicate data stored when using cURL -
i trying post data using curl
web services store data database there, it's storing same data 2 times, instead of one. applied condition there , it's working can not find reason behind behavior.
$postedarray['login_credentials'] = $this->login_data; $postedarray['post_data'] = $this->arrpostdata; $str = http_build_query($postedarray); $ch = curl_init(); curl_setopt($ch, curlopt_httpheader, array('expect:')); curl_setopt($ch, curlopt_url, $this->requesturl); curl_setopt($ch, curlopt_encoding, 'gzip,deflate'); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, $str); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_connecttimeout, 999); curl_setopt($ch, curlopt_timeout, 999); if (curl_exec($ch) === false) { echo 'curl error: ' . curl_error($ch); return false; } $response = curl_exec($ch); $response = json_decode($response, true); curl_close($ch); return $response;
because calling curl_exec 2 times:
if (curl_exec($ch) === false) { echo 'curl error: ' . curl_error($ch); return false; } $response = curl_exec($ch);
the first time while evaluating response inside if, , again after if. 1 should dropped.
Comments
Post a Comment