I want to extract data from this URL with Php Curl:
https://www.traveloka.com/en/flight/fullsearch?ap=JKTA.DPS&dt=14-10-2017.NA&ps=1.0.0&sc=ECONOMY
But I got the following error:
"{"errorType":"SERVER_ERROR","userErrorMessage":"Unexpected server error occurred. We apologize for the inconvenience. Please try again later.","errorMessage":"Exception occurred in server."}".
How I can extract the data from that link with php curl?
Here is my code
$url = 'https://api.traveloka.com/en/v2/flight/search/oneway';
$params = [
'context' => [
'tvLifetime' => 'eTq6r7InDN+j0vrg5Bujah9yFLWfBGsNGWxzjTBUa/jvVfn8fy/IF40U7OQl0vjmoqMJwuSocopqxISYLLi6YlngzuFViHSWhNHdFgs+49yydWXm5gSjBRwDBFuO0UKHd+B69Ip0Tk1qnKH+oyzW43f2GdS7QOd10yBpqoCOyOk73cVe4oyqCjYUR7X72PoHr14UQNQEUjl1NP5Mcxp+1Gw6RzKF7uV7jMRzmsYbGfGKpYLfsYtxaSx1t35KGWOO605YN9Mj2n5kP5fOD7j2KA9adtfLBtEymWXf6tEt3ug8oBVyzj5c2/pp/hboYilQnDRCih+RwhV5WX7hPTw9IsKapSNtWZ1NX8biH7UyYuhNLgcLK03OS4WNpoO+NphjOPKh09oBpUgrEJ0UqeY+1rfj98lWMAdpMO5rp2E5pvmP7HRuW6CqBwSchPLtVPQAi7ceDGYgYneH+AfodZMd5A==',
'tvSession' => '9tCFUug+5pqBk0WdAmwAbThaxD2lAm75JaxFJenJTB2MkEWW7bwVa5FW83NZnCLnlL2TAAijDDIDfD9YbC7NhRws3r5fKxPj62n1bJ+Nck309g3Rkogk+dtxsoMRpFHbkVkEJbYuNFbd9Ckp9iEBGg==',
'nonce' => '5eebdd23-2574-4465-afa7-cecc94b8f909'
],
'clientInterface' => 'desktop',
'data' => [
'currency' => 'IDR',
'destinationAirportOrArea' => 'DPS',
'flightDate' => [
'day' => '14',
'month' => '10',
'year' => '2017'
],
'isReschedule' => 'false',
'locale' => 'en_ID',
'newResult' => 'true',
'numSeats' => [
'numAdults' => '1',
'numChildren' => '0',
'numInfants' => '0'
],
'seatPublishedClass' => 'ECONOMY',
'seqNo' => 'null',
'sortFilter' => [
'filterAirlines' => [],
'filterArrive' => [],
'filterDepart' => [],
'filterTransit' => [],
'selectedDeparture' => '',
'sort' => 'null'
],
'sourceAirportOrArea' => 'JKTA',
'searchId' => 'null',
'usePromoFinder' => 'false',
'useDateFlow' => 'false'
],
'fields' => []
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_REFERER, "https://www.traveloka.com/en/flight/fullsearch?ap=JKTA.DPS&dt=14-10-2017.NA&ps=1.0.0&sc=ECONOMY");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Host: api.traveloka.com",
"Accept: application/json, text/javascript, */*; q=0.01",
"Accept-Language: en-us,en;q=0.5",
"X-Requested-With: XMLHttpRequest",
"Connection: keep-alive",
"Pragma: no-cache",
"Cache-Control: no-cache")
);
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
Actually I'm not doing screen crawling, but I want to crawl its json data. I open the "Network" Tab in browser and see the XHR section, and then I want to grab the response from that XHR section. So how to do it and what's wrong with my code?
As per the URL you have given using the below code, you would get nothing rather the redirection link:
Replace with the link and parameters with the correct api:
General format of using CURL is given here:
$ch = curl_init();
$params = urldecode('{"ap":"' . 'JKTA.DPS' . '","dt":"' . '14-10-2017.NA' . '","ps":"' . '1.0.0'. '","sc":"' . 'ECONOMY'. '"}');
$url = 'https://www.traveloka.com/en/flight/fullsearch?JsonData=' . $params;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
if (!empty($output)) {
$x = json_decode($output, true);
var_dump($x);
}else{
return FALSE;
}
What you want to do is called Web scraping, there are plenty of tools that you can use to do that.
For now, go for:
https://github.com/FriendsOfPHP/Goutte
or https://github.com/duzun/hQuery.php.
Related
I'm trying to post a parameter with cURL,
when I tried with this type of format :
CURLOPT_POSTFIELDS => "label=sample"
I exactly got "label" key in the server with "sample" as its value
but I get it empty in the server when I sent it out as a variable .
CURLOPT_POSTFIELDS => "label=$email"
$curl = curl_init();
$user_info=$this->web_model->retriveUserInfo();
$email=$user_info->email;
curl_setopt_array($curl, array(
CURLOPT_URL => "https://test.bitgo.com/api/v2/".$coin."/wallet/".$wallet_id."/address",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "label=$email",
CURLOPT_HTTPHEADER => array(
"Accept: */*",
"Accept-Encoding: gzip, deflate",
"Authorization: Bearer v2x4e7cf3fb7e6c2e87bf8103e49756b3892b2e350d6cdbaeb65757980",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Content-Length: 11",
"Content-Type: application/x-www-form-urlencoded",
"Host: test.bitgo.com",
"Postman-Token: b3f2ee7c-9a19-479b-bfe2-27000c90e3c7,d611bde9-3eb1-4e2b-b8f5-a7a5f5485726",
"User-Agent: PostmanRuntime/7.15.2",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$response = json_decode($response, true);
$err = curl_error($curl);
curl_close($curl);
my main problem is CURLOPT_POSTFIELDS format for variables !
Doc says about CURLOPT_POSTFIELDS:
This parameter can either be passed as a urlencoded string like 'para1=val1¶2=val2&...' or as an array with the field name as key and field data as value.
So you can:
Replace: CURLOPT_POSTFIELDS => "label=$email", with CURLOPT_POSTFIELDS => ['label' => $email], and if you'll need more data to pass as POST field you can just add another pair $key => $value to that array or prepare it before setting curl options.
Set POST fields via http_build_query:
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); where $ch is curl handle and $data is array of $key => $value pairs where $key is field name.
But keep in mind:
Passing an array to CURLOPT_POSTFIELDS will encode the data as multipart/form-data, while passing a URL-encoded string will encode the data as application/x-www-form-urlencoded.
Many thanks
Finally I had to use Guzzle library simply
$client = new GuzzleHttp\Client(['base_uri' => 'https://test.bitgo.com/api/v2/']);
$response = $client->post($coin.'/wallet/'.$wallet_id.'/address', [
'headers' => [
'Authorization' => 'Bearer v2x4e7cf3fb7e6c2e87bf8103e4975dsddbaeb65ba017b555757980'],
'form_params' => [
"label" => $email
]
very very useful
You can try this
function curl($post = array(), $url, $token = '', $method = "POST", $json = false, $ssl = false){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
if($method == 'POST'){
curl_setopt($ch, CURLOPT_POST, true);
}
if($json == true){
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer '.$token, 'Content-Length: ' . strlen(json_encode($post))));
}else{
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
// Proxy example only
if (!empty($proxy)) {
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:888');
if (!empty($proxyAuth)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password');
}
}
if($ssl == false){
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->statusCode = $statusCode;
if (curl_error($ch)) {
$error = 'CURL_ERROR '.$statusCode.' - '.curl_error($ch);
// print_r('CURL_ERROR '.$statusCode.' - '.curl_error($ch));
throw new Exception('CURL_ERROR '.curl_error($ch), $statusCode);
}
curl_close($ch);
return $response;
}
I want to extract data from this URL with Php Curl:
https://www.traveloka.com/en/flight/fullsearch?ap=JKTA.DPS&dt=14-10-2017.NA&ps=1.0.0&sc=ECONOMY
But I got the following error:
"{"errorType":"SERVER_ERROR","userErrorMessage":"Unexpected server error occurred. We apologize for the inconvenience. Please try again later.","errorMessage":"Exception occurred in server."}".
How I can extract the data from that link with php curl?
Here is my code
$url = 'https://api.traveloka.com/en/v2/flight/search/oneway';
$params = [
'context' => [
'tvLifetime' => 'eTq6r7InDN+j0vrg5Bujah9yFLWfBGsNGWxzjTBUa/jvVfn8fy/IF40U7OQl0vjmoqMJwuSocopqxISYLLi6YlngzuFViHSWhNHdFgs+49yydWXm5gSjBRwDBFuO0UKHd+B69Ip0Tk1qnKH+oyzW43f2GdS7QOd10yBpqoCOyOk73cVe4oyqCjYUR7X72PoHr14UQNQEUjl1NP5Mcxp+1Gw6RzKF7uV7jMRzmsYbGfGKpYLfsYtxaSx1t35KGWOO605YN9Mj2n5kP5fOD7j2KA9adtfLBtEymWXf6tEt3ug8oBVyzj5c2/pp/hboYilQnDRCih+RwhV5WX7hPTw9IsKapSNtWZ1NX8biH7UyYuhNLgcLK03OS4WNpoO+NphjOPKh09oBpUgrEJ0UqeY+1rfj98lWMAdpMO5rp2E5pvmP7HRuW6CqBwSchPLtVPQAi7ceDGYgYneH+AfodZMd5A==',
'tvSession' => '9tCFUug+5pqBk0WdAmwAbThaxD2lAm75JaxFJenJTB2MkEWW7bwVa5FW83NZnCLnlL2TAAijDDIDfD9YbC7NhRws3r5fKxPj62n1bJ+Nck309g3Rkogk+dtxsoMRpFHbkVkEJbYuNFbd9Ckp9iEBGg==',
'nonce' => '5eebdd23-2574-4465-afa7-cecc94b8f909'
],
'clientInterface' => 'desktop',
'data' => [
'currency' => 'IDR',
'destinationAirportOrArea' => 'DPS',
'flightDate' => [
'day' => '14',
'month' => '10',
'year' => '2017'
],
'isReschedule' => 'false',
'locale' => 'en_ID',
'newResult' => 'true',
'numSeats' => [
'numAdults' => '1',
'numChildren' => '0',
'numInfants' => '0'
],
'seatPublishedClass' => 'ECONOMY',
'seqNo' => 'null',
'sortFilter' => [
'filterAirlines' => [],
'filterArrive' => [],
'filterDepart' => [],
'filterTransit' => [],
'selectedDeparture' => '',
'sort' => 'null'
],
'sourceAirportOrArea' => 'JKTA',
'searchId' => 'null',
'usePromoFinder' => 'false',
'useDateFlow' => 'false'
],
'fields' => []
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_REFERER, "https://www.traveloka.com/en/flight/fullsearch?ap=JKTA.DPS&dt=14-10-2017.NA&ps=1.0.0&sc=ECONOMY");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Host: api.traveloka.com",
"Accept: application/json, text/javascript, */*; q=0.01",
"Accept-Language: en-us,en;q=0.5",
"X-Requested-With: XMLHttpRequest",
"Connection: keep-alive",
"Pragma: no-cache",
"Cache-Control: no-cache")
);
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
Actually I'm not doing screen crawling, but I want to crawl its json data. I open the "Network" Tab in browser and see the XHR section, and then I want to grab the response from that XHR section. So how to do it and what's wrong with my code?
As per the URL you have given using the below code, you would get nothing rather the redirection link:
Replace with the link and parameters with the correct api:
General format of using CURL is given here:
$ch = curl_init();
$params = urldecode('{"ap":"' . 'JKTA.DPS' . '","dt":"' . '14-10-2017.NA' . '","ps":"' . '1.0.0'. '","sc":"' . 'ECONOMY'. '"}');
$url = 'https://www.traveloka.com/en/flight/fullsearch?JsonData=' . $params;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
if (!empty($output)) {
$x = json_decode($output, true);
var_dump($x);
}else{
return FALSE;
}
What you want to do is called Web scraping, there are plenty of tools that you can use to do that.
For now, go for:
https://github.com/FriendsOfPHP/Goutte
or https://github.com/duzun/hQuery.php.
How would I write below command in curl php:
curl -XPOST https://apiv2.unificationengine.com/v2/message/send
–data
“{ \"message\”: { \“receivers\”: [{\“name\”: \“TO_NAME \”,
\“address\”: \“TO_EMAILADDRESS\” ,
\“Connector\”: \“UNIQUE_CONNECTION_IDENTIFIER\”,
\“type\”: \“to\”}],\“sender\”: {\“address\”: \“EMAIL_ADDRESS\”},
\“subject\”:\“Hello\”,\“parts\”: [{\“id\”: \“1\”,
\“contentType\”: \“text/plain\”,
\“data\”:\“Hi welcome to UE\” ,
\“size\”: 100,\“type\”: \“body\”,\“sort\”:0}]}}“
-u USER_ACCESSKEY:USER_ACCESSSECRET -k
if this is the right way to execute and write curl in php:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://abcproject.com/tester.phtml");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"postvar1=value1&postvar2=value2&postvar3=value3");
// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS,
// http_build_query(array('postvar1' => 'value1')));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
// further processing ....
if ($server_output == "OK") { ... } else { ... }
Here is more sample code SO question.
But I am finding problem that where to mentions -u, --data options in php curl.
curl -u is equivalent to CURLOPT_USERPWD in php-curl.
You set it with curl_setopt, as the others.
--data is CURLOPT_POSTFIELDS, which you are already sending. But in your case you'd want to populate with the json you want to send.
If you are sending a JSON, you'd do well in setting the Content-type header (and content-length wouldn't be amiss either)
Be careful, in your example call there are some weird characters. But the JSON you posted is equivalent to:
$yourjson = <<<EOF
{
"message": {
"receivers": [
{
"name": "TO_NAME ",
"address": "TO_EMAILADDRESS",
"Connector": "UNIQUE_CONNECTION_IDENTIFIER",
"type": "to"
}
],
"sender": {
"address": "EMAIL_ADDRESS"
},
"subject": "Hello",
"parts": [
{
"id": "1",
"contentType": "text/plain",
"data": "Hi welcome to UE",
"size": 100,
"type": "body",
"sort": 0
}
]
}
}
EOF;
But usually you'd start with your data in array form and json_encode it.
So you'd start with something like:
$array = [
'message' =>
[
'receivers' =>
[
0 =>
[
'name' => 'TO_NAME ',
'address' => 'TO_EMAILADDRESS',
'Connector' => 'UNIQUE_CONNECTION_IDENTIFIER',
'type' => 'to',
],
],
'sender' =>
[
'address' => 'EMAIL_ADDRESS',
],
'subject' => 'Hello',
'parts' =>
[
0 =>
[
'id' => '1',
'contentType' => 'text/plain',
'data' => 'Hi welcome to UE',
'size' => 100,
'type' => 'body',
'sort' => 0,
],
],
],
];
... convert that using $yourjson = json_encode($array), and that's it.
E.g.:
// you already have your json inside of $yourjson,
// plus your username and password in their respective variables.
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, $yourjson);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($yourjson)
]
);
to send data as JSON add header content-type and set as JSON and add the option CURLOPT_USERPWD, something like this:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://apiv2.unificationengine.com/v2/message/send");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS,
“{ \"message\”: { \“receivers\”: [{\“name\”: \“TO_NAME \”, \“address\”: \“TO_EMAILADDRESS\” , \“Connector\”: \“UNIQUE_CONNECTION_IDENTIFIER\”, \“type\”: \“to\”}],\“sender\”: {\“address\”: \“EMAIL_ADDRESS\”},\“subject\”:\“Hello\”,\“parts\”: [{\“id\”: \“1\”,\“contentType\”: \“text/plain\”, \“data\”:\“Hi welcome to UE\” ,\“size\”: 100,\“type\”: \“body\”,\“sort\”:0}]}}“);
// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS,
// http_build_query(array('postvar1' => 'value1')));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$server_output = curl_exec ($ch);
curl_close ($ch);
I am able to get the GET request working but having issues related to authentication in POST and PUT request. I am getting the error "You must log in before using this part of Bugzilla". I have provided the correct username and password. I have tried CURLAUTH_ANY as well as CURLAUTH_BASIC. I have tried both PUT and POST request. Any help is appreciated.
$url ="http://localhost:8080/bugzilla/rest/bug/2";
$apikey = "IZC4rs2gstCal0jEZosFjDBRV9AQv2gF0udh4hgq";
$data = array(
"product" => "TestProduct",
"component" => "TestComponent",
"version" => "unspecified",
"summary" => "This is a test bug - please disregard",
"alias" => "SomeAlias",
"op_sys" => "All",
"priority" => "P1",
"rep_platform" => "All"
);
$str_data = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$str_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-Type: application/json", "Accept: application/json"));
$username = 'ashish.sureka#in.abb.com';
$password = 'abbincrc';
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo $result
Following code solved my problem. I have written a blog on it which might be useful to others encountering the same problem.
<?php
$url = 'http://localhost:8080//bugzilla/xmlrpc.cgi';
$ch = curl_init();
$header = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt_array($ch, $header);
$bugreport = array(
'login' => 'ashish.sureka#in.abb.com',
'password' => 'abbincrc',
'product' => "TestProduct",
'component' => "TestComponent",
'summary' => "Bug Title : A One Line Summary",
'assigned_to' => "ashish.sureka#in.abb.com",
'version' => "unspecified",
'description' => "Bug Description : A Detailed Problem Description",
'op_sys' => "All",
'platform' => "All",
'priority' => "Normal",
'severity' => "Trivial"
);
$request = xmlrpc_encode_request("Bug.create", $bugreport);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_exec($ch)
?>
$postdata = array(
'method' => 'post',
'key' => $apikey,
'file' => new \CurlFile($filename,'image/jpg'),
'phrase' => $is_phrase,
'regsense' => $is_regsense,
'numeric' => $is_numeric,
'min_len' => $min_len,
'max_len' => $max_len,
'is_russian' => $is_russian
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://$domain/in.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$result = curl_exec($ch);
The result response is:
Uncaught Error: Class 'CurlFile' not found in ...
Im running on PHP7.
So why?
The curl plugin should be properly installed. The same can be verified using phpinfo()