Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading a file with cURL by using POST returns error "Bad Request (Invalid Number)"
    primarykey
    data
    text
    <p>I am attempting to upload a file using php to a website that allows files to be uploaded through a form. When I try to run the code, I get a "Bad Request (Invalid Number)" error. Then when I enabled the cURL to fail on error with <code>CURLOPT_FAILONERROR</code> I get a "400 error". I think I've typed in everything correctly, I've downloaded files from the same website on a similar form they have.</p> <pre><code>$Submitted_ImportFile = realpath($Submitted_ImportFile); $postdata = array( 'NOSAVE___Form_Submission_Token' =&gt; $NOSAVE___Form_Submission_Token, 'import_type' =&gt; $import_type, 'span_Customers_BillingAddresses' =&gt; $Customers_BillingAddresses, 'span_Customers_ShippingAddresses' =&gt; $Customers_ShippingAddresses, 'span_TrackingNumbers_status' =&gt; $TrackingNumbers_status, 'span_TrackingNumbers_email' =&gt; $TrackingNumbers_email, 'Submitted_ImportFile' =&gt; '@'.$Submitted_ImportFile, 'OVERWRITE' =&gt; $OVERWRITE, 'Submit' =&gt; 'Upload my files' ); foreach ($postdata as $key =&gt; $value) { if (strlen($value) &lt; 1) { unset($postdata[$key]); }; }; // $postdata_encoded = http_build_query($postdata).'&amp;Submitted_ImportFile=@'.$Submitted_ImportFile; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url.'admin/db_import.asp?UploadID='.$UploadID); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0'); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt ($ch, CURLOPT_REFERER, $url); // curl_setopt ($ch,CURLOPT_FAILONERROR, true); // Temporarly added to diagnose issue curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $output = curl_exec ($ch); // $error = curl_error($ch); // Returns a 400 error </code></pre> <p>Here is the array containing all the POST data that is sent:</p> <pre><code>Array ( [NOSAVE___Form_Submission_Token] =&gt; 0D047D55CF3644818EBFEEEF607AD65D [import_type] =&gt; Customers [Submitted_ImportFile] =&gt; @/home/kudchcx/public_html/alpha_test/Customers_test.csv [OVERWRITE] =&gt; Y [Submit] =&gt; Upload my files ) </code></pre> <p>I've checked the website forms and used javascript to make sure I have all the necessary fields. I am at a loss for this issue.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload