Curl POST phpból nem megy, parancssorból igen

Curl POST phpból nem megy, parancssorból igen
2020-02-20T10:09:15+01:00
2020-02-20T10:30:47+01:00
2022-10-15T21:26:09+02:00
stibro1977
Sziasztok,

ha parancssorból adom ki az alábbi parancsot, sikeresen lefut:

curl -X POST "https://api.valami.com/api/Login" -H "accept: application/json" -H "Content-Type: application/json" -d "{"vendorID":"123456","ekx":"789101","secret":"csilllag","password":"titkos"}"
viszont ha php scriptből próbálom, nem járok sikerrel:
Unexpected character encountered while parsing value: v. Path '', line 0, position 0.

Array ( => https://api.valami.com/api/Login [content_type] => application/json; charset=utf-8 [http_code] => 400 [header_size] => 224 [request_size] => 289 [filetime] => -1 [ssl_verify_result] => 20 [redirect_count] => 0 [total_time] => 0.233461 [namelookup_time] => 0.002318 [connect_time] => 0.030936 [pretransfer_time] => 0.129261 [size_upload] => 100 [size_download] => 164 [speed_download] => 703 [speed_upload] => 429 [download_content_length] => -1 [upload_content_length] => 100 [starttransfer_time] => 0.233326 [redirect_time] => 0 [redirect_url] => [primary_ip] => 80.156.201.29 [certinfo] => Array ( ) [primary_port] => 443 [local_ip] => 172.29.26.162 [local_port] => 56497 [http_version] => 2 [protocol] => 2 [ssl_verifyresult] => 0 [scheme] => HTTPS [appconnect_time_us] => 128972 [connect_time_us] => 30936 [namelookup_time_us] => 2318 [pretransfer_time_us] => 129261 [redirect_time_us] => 0 [starttransfer_time_us] => 233326 [total_time_us] => 233461 [errno] => 0 [errmsg] => [content] => 1 )



a kód, meg így néz ki:

function get_web_page( $url,$curl_data ) { $options = array( CURLOPT_RETURNTRANSFER => false, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => false, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects CURLOPT_POST => 1, // i am sending post data CURLOPT_POSTFIELDS => $curl_data, // this are my post vars CURLOPT_SSL_VERIFYHOST => 0, // don't verify ssl CURLOPT_SSL_VERIFYPEER => false, // CURLOPT_VERBOSE => 1, // CURLOPT_HTTPHEADER => array('accept: application/json', 'Content-Type: application/json') ); $ch = curl_init($url); curl_setopt_array($ch,$options); $content = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch) ; $header = curl_getinfo($ch); curl_close($ch); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } if (!function_exists('curl_init')){ return 'Sorry cURL is not installed!'; } $url = 'https://api.valami.com/api/Login'; $curl_data = 'vendorID=123456&ekp=789101&secret=csillag&password=titkos'; //$curl_data = ''; $response = get_web_page($url,$curl_data); print_r($response);

köszönöm a segítséget
Mutasd a teljes hozzászólást!
Próbálj meg json-t átadni:

$curl_data = json_encode(array( 'vendorID' => 123456, 'ekp' => 789101, 'secret' => 'csillag', 'password' => 'titkos' ));
illetve a php-ben ekp van, fentiben pedig ekx - nem tudom számít-e
Mutasd a teljes hozzászólást!

Tetszett amit olvastál? Szeretnél a jövőben is értesülni a hasonló érdekességekről?
abcd