ixudra / curl

Custom PHP curl library for the Laravel 5 framework - developed by Ixudra

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

kelvins19 opened this issue · comments

    $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!

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

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.