ixudra / curl

Custom PHP curl library for the Laravel 5 framework - developed by Ixudra
MIT License
562 stars 128 forks source link

How to Curl (ContentType: multipart/form-data) to API without file data? #125

Open kelvins19 opened 3 years ago

kelvins19 commented 3 years ago
    $jsonField = [
        'user_id'       => 'userid',
        'document_id'   => 'documentid', 
    ];
    $jsonFile = ['JSONFile' => $jsonField];

    $output = Curl::to('$url')
        ->withHeader('Authorization:Bearer ' . $token)
        ->withContentType('multipart/form-data')
        ->withData([
            'jsonfield'     => json_encode($jsonFile)
        ])->asJsonResponse()
        ->post();

Hi, I have been trying to send request to API server, it requires multipart field as its ContentType. But when i checked with the API provider, they said that the json data is not been received in their server, only the header. I have used this method for other API request that they have and it works well. The only difference is that the other have file upload and this one doesn't. Does anyone have experienced this? Any solution / help will be appreciated. Thanks!

elimentz commented 3 years ago

Can you ask the API provider to give you a native cURL example of what the syntax should look like? If you have that, it should be pretty easy to transfer that into the package syntax

kelvins19 commented 3 years ago

Can you ask the API provider to give you a native cURL example of what the syntax should look like? If you have that, it should be pretty easy to transfer that into the package syntax

I have asked them, unfortunately they don't have any examples yet.