Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support -F and --form option #27

Merged
merged 1 commit into from
Jul 10, 2020
Merged

Conversation

alamirault
Copy link

This PR allow to convert curl to php with options -F and --form.
Example:

curl -X POST https://api.easypost.com/v2/shipments \
     -u API_KEY: \
     -F 'field[0]=value1' \
     -F 'field[1]=@myFile.png'

is converted as

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.easypost.com/v2/shipments');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
    'field[0]' => 'value1',
    'field[1]' => '@' .realpath('myFile.png')
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_USERPWD, 'API_KEY' . ':' . '');

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

If this PR is merged, issue #26 can be closed

@r-akshat
Copy link

Hi @incarnate, Are you planning to merge this issue anytime soon ?

@incarnate incarnate merged commit 47e0fed into incarnate:gh-pages Jul 10, 2020
@incarnate
Copy link
Owner

Sorry for the slow review, looks good, thanks for the contribution @alamirault

This was referenced Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants