Please help me how to transfer this data using php cURL in a simplified way:

------WebKitFormBoundarymTkgTwzpBHQLP12d Content-Disposition: form-data; name="YII_CSRF_TOKEN" dc757ad2e3d6523231c82e302d377e3b6ba702f2 ------WebKitFormBoundarymTkgTwzpBHQLP12d Content-Disposition: form-data; name="widgetId" messager ------WebKitFormBoundarymTkgTwzpBHQLP12d Content-Disposition: form-data; name="MessageForm[network]" 38050 ------WebKitFormBoundarymTkgTwzpBHQLP12d Content-Disposition: form-data; name="MessageForm[phone]" 546-45-65 ------WebKitFormBoundarymTkgTwzpBHQLP12d Content-Disposition: form-data; name="MessageForm[encoding]" cyrilic ------WebKitFormBoundarymTkgTwzpBHQLP12d Content-Disposition: form-data; name="MessageForm[is_translit]" 0 ------WebKitFormBoundarymTkgTwzpBHQLP12d Content-Disposition: form-data; name="MessageForm[message]" ваиави ------WebKitFormBoundarymTkgTwzpBHQLP12d Content-Disposition: form-data; name="MessageForm[verifyCode]" 930 ------WebKitFormBoundarymTkgTwzpBHQLP12d-- 

    2 answers 2

    Regarding PHP cURL:

    If you don’t have a specific boundary (because it’s supposed to be generated randomly), then it’s pretty banal:

     curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'widgetId' => 'messager', 'MessageForm[id]' => 1, // ну и аналогично ]); 

    Generates a query like this:

     POST / HTTP/1.1 Host: 127.0.0.1:8080 Accept: */* Content-Length: 256 Expect: 100-continue Content-Type: multipart/form-data; boundary=------------------------5e95fe2dd0851b9a --------------------------5e95fe2dd0851b9a Content-Disposition: form-data; name="widgetId" messager --------------------------5e95fe2dd0851b9a Content-Disposition: form-data; name="MessageForm[id]" 1 --------------------------5e95fe2dd0851b9a-- 

    If CURLOPT_POSTFIELDS array, then multipart/form-data generated by default.

    If you need to control the separator for any purpose, you will have to format the message body yourself into a large string, but transfer all the same to CURLOPT_POSTFIELDS . If a string is passed to this parameter, it is sent as is.

      like so

       curl -X POST -H "<header_#_1> : <header_#_1_value>" -H "<header_#_2> : <header_#_2_value>" -H "Cache-Control: no-cache" -H "Postman-Token: 58708f45-232e-e4d1-8dd7-1728e0c32a77" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F "file=@<path_to_my_file>" "<my_url>"