Hello ! Tell me please, is it possible to somehow see which POST request generates curl by the passed parameters?

  • An example in the studio! - Nick Volynkin
  • So send a request to your test url, in which register var_dump ($ _ POST) and write to a file or see the answer through curl. In general, you can create the post line yourself via http_build_query - ilyaplot
  • @ilyaplot, and if the request is generated for multipart / form-data? The browser returns: ------WebKitFormBoundaryibLm7G5cqxCOuAFy Content-Disposition: form-data; name="file"; filename="1-g-0-032-oz-silver-valcambi-bullion-bar-999-rev.jpg" Content-Type: image/jpeg ------WebKitFormBoundaryibLm7G5cqxCOuAFy Content-Disposition: form-data; name="scrid" 32482346-7100587438898460646 ------WebKitFormBoundaryibLm7G5cqxCOuAFy-- ------WebKitFormBoundaryibLm7G5cqxCOuAFy Content-Disposition: form-data; name="file"; filename="1-g-0-032-oz-silver-valcambi-bullion-bar-999-rev.jpg" Content-Type: image/jpeg ------WebKitFormBoundaryibLm7G5cqxCOuAFy Content-Disposition: form-data; name="scrid" 32482346-7100587438898460646 ------WebKitFormBoundaryibLm7G5cqxCOuAFy-- ------WebKitFormBoundaryibLm7G5cqxCOuAFy Content-Disposition: form-data; name="file"; filename="1-g-0-032-oz-silver-valcambi-bullion-bar-999-rev.jpg" Content-Type: image/jpeg ------WebKitFormBoundaryibLm7G5cqxCOuAFy Content-Disposition: form-data; name="scrid" 32482346-7100587438898460646 ------WebKitFormBoundaryibLm7G5cqxCOuAFy-- question is, can I see what will be generated when sent to the server to compare the request and the answer. I apologize for the formatting. - Bogdan Gudyma

2 answers 2

No, unfortunately, the curl extension does not have such a native capability. But you can send a request somewhere to the program under your control and see what exactly came. For example, the simplest way is to open the port via nc :

 nc -l -p 12345 

Then in the code, replace the URL with this local address:

 $ch = curl_init('http://127.0.0.1:12345'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => ['foo' => 1], ]); $response = curl_exec($ch); 

When you run this code, the exact request sent will appear on the console with nc :

 melkij@melkij:~$ nc -l -p 12345 POST / HTTP/1.1 Host: 127.0.0.1:12345 Accept: */* Content-Length: 139 Expect: 100-continue Content-Type: multipart/form-data; boundary=------------------------05be5d432625f809 --------------------------05be5d432625f809 Content-Disposition: form-data; name="foo" 1 --------------------------05be5d432625f809-- 
  • Thank you Helped - Bogdan Gudyma

Use the -v option

 curl -v google.com