CURL using PHP

Asked

Viewed 2,104 times

-2

I have this command on Windows cmd:

C:\Users\Jhon\Desktop>curl -k -u username:senha https://analysiscenter.veracode.com/api/3.0/generateflawreport.do -F "app_id_list=000000" -F "scan_type=static"

I would like to get the results by importing into PHP, but I don’t know how to do it.

Please, can someone help me?

Thank you.

  • Start by studying PHP; later by studying the native Curl library in it. After that you will be able to try to do it yourself and, if you cannot, you can [Dit] your question with more details of your attempt. Without this, your question comes very close to a "do it for me" question, which is not well received by the community.

1 answer

0


You can see in the documentation what is equivalent for each command:

Curl -k -u username:password https://analysiscenter.veracode.com/api/3.0/generateflawreport.do -F "app_id_list=000000" -F "scan_type=Static


-k (It is not recommended to use)

CURLOPT_SSL_VERIFYPEER (definido para FALSE)
CURLOPT_SSL_VERIFYHOST (definido para FALSE)

-u

CURLOPT_USERPWD

-f

CURLOPT_POST
CURLOPT_POSTFIELDS (usando array para multipart/form-data)

In the end you’ll have something like:

// URL:
$ch = curl_init('https://analysiscenter.veracode.com/api/3.0/generateflawreport.do');

// Obter retorno em $resultado:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// -F
// Definir como POST:
curl_setopt($ch, CURLOPT_POST, true);

// -F
// Definir corpo, como multipart/form-data:
curl_setopt($ch, CURLOPT_POSTFIELDS, ['app_id_list' => '000000','scan_type' => 'static']);

// -u
// Definir o usuário/senha do HTTP Basic Authentication:
curl_setopt($ch, CURLOPT_USERPWD, 'username'.':'.'senha');

// -k
// Desligar a verificação do TLS (não é recomendado usar isto para FALSE!):
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);


$resultado = curl_exec($ch);
curl_close ($ch);

// Visualizar resultado:
var_dump($resultado);

You can see in detail the functions in http://php.net/manual/en/function.curl-setopt.php, on this page you will have all the CURLOPT_* which you can use. Some may be missing, so see also https://curl.haxx.se/libcurl/c/curl_easy_setopt.html for more details on each command. Remember to update Curl to the latest version, so you can use all resources.

  • Thank you @Inkeliz, it worked perfectly. Thank you so much for your help. abs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.