Answer the question
In order to leave comments, you need to log in
Is it correct to pass XML using cURL php?
I form xml and pass it as a parameter to the function that sends a POST request using cURL, and when I display a variable with my XML in the function that should send the request, I get the line there:
string(793) " CampaignId EQUALS 191853 Date Clicks Cost AdNetworkType Date Campaign #191853, August CUSTOM_REPORT THIS_MONTH TSV NO NO "
function custom_report( ) {
$service = "reports";
$data ='<?xml version="1.0" encoding="UTF-8"?>
<ReportDefinition xmlns="https://api.direct.yandex.com/v5/reports">
<SelectionCriteria>
<Filter>
<Field>CampaignId</Field>
<Operator>EQUALS</Operator>
<Values>191853</Values>
</Filter>
</SelectionCriteria>
<FieldNames>Date</FieldNames>
<FieldNames>Clicks</FieldNames>
<FieldNames>Cost</FieldNames>
<FieldNames>AdNetworkType</FieldNames>
<OrderBy>
<Field>Date</Field>
</OrderBy>
<ReportName>Campaign #191853, August</ReportName>
<ReportType>CUSTOM_REPORT</ReportType>
<DateRangeType>THIS_MONTH</DateRangeType>
<Format>TSV</Format>
<IncludeVAT>NO</IncludeVAT>
<IncludeDiscount>NO</IncludeDiscount>
</ReportDefinition>';
return QueryToYandex( $service, $data );
}
function QueryToYandex( $service, $data ) {
var_dump($data); //здесь получаю строку
$tokenYandex = "";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-sandbox.direct.yandex.com/v5/".$service,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"accept-language: ru",
"authorization: Bearer ".$tokenYandex,
"Client-Login: asdsad",
"processingMode: online",
"returnMoneyInMicros: false"
),
)
);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$res = curl_exec($curl);
if(!$res){
$error = curl_error($curl).'('.curl_errno($curl).')';
$res = $error;
}
else
curl_close($curl);
return $res;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question