Send form data curl php
I have the following command, which uses the --form/--F option, which I know to be working: Show
I need to run this command via php, but I'm having trouble, presumably with the form file data. I tried the following, however echoing or var_dumping the result seems to show nothing, just a blank page or a blank string.
How can I get this command working in PHP? asked Oct 17, 2017 at 15:21
KinsDotNetKinsDotNet 1,4985 gold badges24 silver badges49 bronze badges 3 since no answer got it right thus far (at least not with an approach that would work in php 5.6+), here goes: the equivalent php curl_ code would be:
(i would also recommend setting CURLOPT_ENCODING to emptystring, especially if you expect the response to be compressible, that would be the equivalent of adding answered Oct 22, 2017 at 10:04
hanshenrikhanshenrik 18.1k3 gold badges39 silver badges77 bronze badges try this:
answered Oct 20, 2017 at 9:22
jelle woordjelle woord 1832 silver badges16 bronze badges 0 One way is to use
answered Oct 20, 2017 at 14:41 2 Maybe something like this could work:
answered Oct 20, 2017 at 13:54
0
answered Jan 21, 2021 at 11:44
JuniorJunior 1,1713 gold badges13 silver badges25 bronze badges You need to read file data and then attach data on post fields. Try this, this should work. If doesn't work, make sure
answered Oct 22, 2017 at 12:00
3 How does curl send form data?To post form data with Curl, you can use one of two command-line parameters: -F (--form) or -d (--data). The -F command-line parameter sends form data with the multipart/form-data content type, and the -d command-line parameter sends form data with the application/x-www-form-urlencoded content type.
How do I send a curl request?To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option.
How do you send a multipart file in curl?With curl, you add each separate multipart with one -F (or --form ) flag and you then continue and add one -F for every input field in the form that you want to send. The above small example form has two parts, one named 'person' that is a plain text field and one named 'secret' that is a file.
What is Curlopt_postfields?CURLOPT_POSTFIELDS. The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ';type=mimetype'.
|