4

I'm working on debugging cURL calls in an application (PHP-based, specifically), and would really like to test identical calls via the command line. The application uses many CURLOPTS, and some of them don't obviously map onto command line flags.

For example, CURLOPT_POSTFIELDS maps onto --data, and CURLOPT_HEADER=1 maps to --include (I actually need CURLOPT_HEADER=0, which I haven't figured out yet).

Is there any documentation that maps the CLI flags onto the the CURLOPT_* constants? There are more options I haven't gotten to yet, so I'm not looking for just a single answer about a particular option.

thelr
  • 93
  • take into consideration also the stackoverflow community for your question. See: https://meta.superuser.com/questions/4836/what-is-the-difference-between-super-user-and-stack-overflow I quote: "Stack Overflow is for programmers, Super User is for computer hardware & software enthusiasts and power users. You want to ask questions about code, go to SO. If you're having a problem with booting your laptop, go to SU." – 1NN May 07 '20 at 19:24
  • Pimp Juice IT accurately sums up my decision to post it here. The CURLOPT constants seem best documented in PHP, but they are actually defined by libcurl. I am also assuming the curl command uses libcurl. – thelr May 13 '20 at 15:49

2 Answers2

4

The Stack Overflow post Convert command line cURL to PHP cURL has this answer which is extremely detailed with links. Note that the correlation is not always one-to-one.

Note that this only lists somewhat exact matches of --long options to similarly named CURLOPT_ constants. But it should give you enough hints on how to compare the curl --help output and the PHP curl_setopt() list.

harrymc
  • 480,290
  • That is an extensive list, but isn't complete or fully correct. It corresponds CURLOPT_HEADER (one of the options mentioned in the question) to --header, when it actually correlates to --include (if set to 1). I don't know what it correlates to if set to 0. – thelr May 13 '20 at 15:53
  • I'm unsure about CURLOPT_HEADER=--include. The libcurl doc, section "Provide a header without contents", CURLOPT_HEADER approach is described as a way of sending extra headers to the server, not of receiving more data. The CURLOPT_HEADER doc also describes it as "set to 1 to ask libcurl to include the headers in the write callback", not read callback. man --include is described as "Include the HTTP response headers in the output". – harrymc May 13 '20 at 16:29
  • In the libcurl doc you linked, section "Provide a header without contents" is talking about CURLOPT_HTTPHEADER, not CURLOPT_HEADER. You might be right that it isn't equivalent to --include, but it's the closest I could find. – thelr May 13 '20 at 18:13
  • 1
    I was referring to the sentence found under "Referrer" which says "It is a normal header so you can set it yourself with the CURLOPT_HEADER approach as shown above". This sentence was actually my first hint that the difference between the two was as between input and output. The above list is not too bad, except that the guy did too good a job, listing everything possible in all situations. He doesn't have --include listed, a pity. – harrymc May 13 '20 at 19:26
2

Looking over curl_setopt and all the options [CURLOPT_XXX] there, you can correlate from the curl(1) - Linux man page documentation and look over the "Options" section and detail of each parameter there to determine what relates to any specific command line option if applicable you may need to utilize.


For example, where CURLOPT_POSTFIELDS maps onto --data on the CLI, you can see per the curl(1) - Linux man page...

  • -d/--data <data>

    (HTTP) Sends the specified data in a POST request to the HTTP server...

...and then from curl_setopt

  • CURLOPT_POSTFIELDS

    The full data to post in a HTTP "POST" operation. ...

For sending POST requests to the HTTP server using curl command line you correlate the two based on the "POST" for the 'request' CLI and 'operation' from the HTTP server.


So based on what type of data or command line options you are working with whatever logic you are building with the curl, PHP, and HTTP operations, the documentation required to map those out already exists in those two sources which will help.

I cannot find an already existing mapping document/resource with this correlation, but I was able to find those existing documents/resources to use for building such a correlated mapped list.

So when you ask is there any documentation that maps the CLI flags onto the the CURLOPT_ constants*... Yes there is and I provided you a couple resources and a small example.

Tip: Using Ctrl+F to search for keywords on each resource per whatever keyword is applicable to the HTTP operation or curl request you are performing\researching may be useful.


Supporting Resources

  • @thelr Unless some list already exists that someone can share with you, building a list to correlate may be tedious and is just a trivial matter really, but for the documentation/resources to build such a list, I've provided some guidance as such. If anyone wants to use this strategy to build you a list, they deserve the bounty for certain, I'm just giving you some guidance and tips to use for whatever you are doing with your commands and such and a way to use those resources as-is as you work on your logic, or to use for building a correlated list. Good luck regardless! – Vomit IT - Chunky Mess Style May 08 '20 at 15:11
  • Thanks! I've tried this method some already, but (as you said) it gets very tedious if the keyword is particularly common ("data" and "header" are good examples of that). I was hoping someone new of something doc created by the devs of either libcurl (the source of the CURLOPTS_*) or the curl binary. – thelr May 13 '20 at 15:42
  • Also, the method doesn't get me an answer for everything - specific example (mentioned in the question): CURLOPT_HEADER=1 is the same as --include, but i can't find a correlation for CURLOPT_HEADER=0. I could have asked for just that, of course, but figured finding comprehensive documentation was a more helpful ask. – thelr May 13 '20 at 15:54