11

There at many threads on converting command line curl commands to php cURL resources. I need to do the opposite. I'm trying to debug some critical vendor code and would like to do a diff. Is this possible? In chrome, when a network request fires, you can copy the network request as a curl command (single string!). I am hoping the php curl lib may offer something similar?

josliber
  • 43,891
  • 12
  • 98
  • 133
cdaringe
  • 1,274
  • 2
  • 15
  • 33
  • There's no automatism for that. Just look at the [manpage](http://curl.haxx.se/docs/manpage.html) and translate the options yourself. Or is this about a specific parameter? – mario May 28 '15 at 21:26
  • i didn't build the **large** curl code segments involved in this problem. instead of reverse engineering the curl resource construction, I was hoping to just do a diff on their command output to determine the changed parameter. sounds like that may not be feasible. I'll go ahead and dig in then. Thx! – cdaringe May 29 '15 at 19:16
  • 1
    I'm not sure it will provide exactly what you're looking for, but enabling CURLOPT_VERBOSE may provide some helpful insight. If you don't have access to STD_ERR output (i.e. you're not running on command line), you can redirect output to a file using CURLOPT_STDERR. – Brady Emerson Sep 16 '15 at 17:58
  • Would it be of any value to try POSTMAN from Chrome Tools? I have found it to be a good way to test input params vs expected output. – Adam T Sep 25 '15 at 01:01
  • An possibility could also be the use of an network sniffer (e.g. wireshark) to analyze directly the HTTP communication done by curl. – Marko Oct 05 '15 at 20:44
  • Does this answer your question? [How to convert Php CURL request to command line curl](https://stackoverflow.com/questions/42671535/how-to-convert-php-curl-request-to-command-line-curl) – Potherca May 31 '22 at 10:31

3 Answers3

0

You can use Chrome "Developer Tool" (Open with F11). Then you will see "network" tab. Open this before you visit wanted url. Inside this tab you will see all request to this domain. Click on the first request and on the right you will see another tabs "headers", "preview", "response", "cookies", "timing". In "headers" tab are headers sent in http for this page. This headers you can use in curl.

EDITED -> If communication is without UI, You need some proxy software like: http://proxyworkbench.com/

fico7489
  • 7,931
  • 7
  • 55
  • 89
-1

Steps

  1. install fiddler and enable it to listen to port 8888(by default)
  2. Change php server side curl domain code and make sure the new domain is pointing to localhost:8888. This way all traffic is routed through fiddler
  3. Capture the request and take a session copy
  4. compare the versions
Faiz Mohamed Haneef
  • 3,418
  • 4
  • 31
  • 41
  • A word of warning on this answer - I'm not familiar with the fiddler software but I went ahead and installed it - now my internet connection only works while I have this software running - I am now figuring out how to fix that up -- but for others : DO NOT USE THIS ANSWER UNLESS YOU KNOW WHAT YOU ARE DOING AND UNDERSTAND THE IMPLICATIONS – kris Jun 08 '17 at 00:28
  • 1
    fiddler is just a proxy sitting between your browser and internet. You should uninstall if you dont understand to use fiddler – Faiz Mohamed Haneef Jun 08 '17 at 20:04
-4

Please note that the following answer is just a work-around, there's no such library for PHP (yet)!


You can convert cURL commands to PHP code with incarnate's cURL-to-PHP tool. It is available online at: https://incarnate.github.io/curl-to-php/

The converter logic is written in JavaScript, you can check its source code on the project's git repository: https://github.com/incarnate/curl-to-php

danronmoon
  • 3,814
  • 5
  • 34
  • 56
Gergely Lukacsy
  • 2,881
  • 2
  • 23
  • 28