0

Hi I am newbie for php and curl.I want to convert following command line curl php curl.I have searched and got some options on following link. http://www.whatsmyip.org/lib/php-curl-option-guide/

But i have a problem on converting the metdata part .

curl -X POST -H "Content-Type: multipart/form-data" \ -F 'metadata={"description":"YaRetail Taxonomy"}' \ -F '[email protected];type=application/json' \ datax.yahooapis.com/v1/taxonomy

1 Answer 1

1

You just use the CURLOPT_POSTFIELDS, example:

$multipartData = array(
    'metadata={"description":"YaRetail Taxonomy"}',
    '[email protected];type=application/json'
);

$headers = array("Content-Type: multipart/form-data");

$ch = curl_init('http://random.url');
curl_setopt($curlSession, CURLOPT_POST, true);
curl_setopt($curlSession, CURLOPT_POSTFIELDS, http_build_query($multipartData));
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

NOTE: I did not test the code so you should check it first.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.