M
M
maryst19862020-10-05 14:09:09
PHP
maryst1986, 2020-10-05 14:09:09

Why does curl work in postman, but not on the server?

why does it work in Postman and get a successful result, but when copying the finished curl code to the site, which this Postman itself generates, does not work?
here is the code that postman gives

<?php
error_reporting(E_ALL);

$curl = curl_init();

assert(curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.sbis.ru/retail/sale/create",
 CURLOPT_AUTOREFERER => true,
CURLOPT_BINARYTRANSFER => true,
CURLOPT_COOKIESESSION => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_FORBID_REUSE => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 11,
CURLOPT_ENCODING=>"",
CURLOPT_USERAGENT=>	$_SERVER["HTTP_USER_AGENT"],
  CURLOPT_MAXREDIRS => 10,
CURLOPT_COOKIE => 'sid=СЮДАКУКИ',
  CURLOPT_POST=>true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
        
  CURLOPT_POSTFIELDS => array ("companyID" => "СВОЕcompanyID", 
"cashierFIO"=> "ФИОКАССИРА", "operationType"=> "1", "cashSum"=> "100", "bankSum"=> null, "internetSum"=> null, "accountSum"=> null, "postpaySum"=> null, "prepaySum"=> null, "vatNone"=> "100", "vatSum0"=> null, "vatSum10"=> null, "vatSum20"=> null, "vatSum110"=> null, "vatSum120"=> null, "allowRetailPayed"=> "1", "nomenclatures"=> array ( "nameNomenclature"=> "Товар для животных в ассортименте", "barcodeNomenclature"=> "95211", "priceNomenclature"=> "100", "quantityNomenclature"=> "1", "measureNomenclature"=> "ШТ", "kindNomenclature"=> "Т", "totalPriceNomenclature"=> "100", "taxRateNomenclature"=> "0", "totalVat"=> "100" ), "customerFIO"=> null, "customerEmail"=> null, "customerPhone"=> null, "customerINN"=> null, "customerExtId"=> null, "taxSystem"=> "8", "sendEmail"=> "[email protected]", "sendPhone"=> null, "propName"=> null, "propVal"=> null, "comment"=> "тестовый чек", "payMethod"=> "4"),
  CURLOPT_HTTPHEADER => array("Content-Type: application/json; charset=utf-8",
    "X-SBISAccessToken: ТОКЕНСЮДАВПИШИТЕ\r\n"."Content-Length: 67\r\n"."Content-Disposition: inline; filename*=UTF-8\r\n"
  ),
)));

$response = curl_exec($curl);
print_r(curl_getinfo($curl));<code lang="php">

//echo $curl;
curl_close($curl); 

</code>
вот ответ 
curl info

Array ( [url] => https://api.sbis.ru/retail/sale/create [content_type] => application/json; charset=utf-8 [http_code] => 500 [header_size] => 780 [request_size] => 632 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.441873 [namelookup_time] => 0.028462 [connect_time] => 0.046011 [pretransfer_time] => 0.209743 [size_upload] => 0 [size_download] => 690 [speed_download] => 1561 [speed_upload] => 0 [download_content_length] => 690 [upload_content_length] => 2965 [starttransfer_time] => 0.441774 [redirect_time] => 0 [certinfo] => Array ( ) [redirect_url] => )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Spol50, 2020-10-15
@Spol50

I also write a check registration script.
Please tell me where did you get the CompanyID ?? ? even in the support service they couldn’t tell me where to get it ... they don’t have an API support service.

M
maryst1986, 2020-10-15
@maryst1986

By the way ... if suddenly someone helps. the problem was in the encoding of the script file itself on the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question