Solved

PHP: Convert use curl code with PHP to post data

Posted on 2013-11-01
1
1,436 Views
Last Modified: 2013-11-03
This works from a Linux command line:
curl -X POST http://zurv3aqzm.iriscouch.com/zzz -d '{"xyz":"Hello World"}' -H "Content-Type: application/json"

Open in new window

How can I do the same thing using cURL for PHP?
0
Comment
Question by:hankknight
1 Comment
 
LVL 12

Accepted Solution

by:
adrian_brooks earned 500 total points
ID: 39618353
<?php
// create new cURL resource

$ch = curl_init();

// set URL and other appropriate options
$options = array(CURLOPT_URL => 'http://www.example.com/',
                 CURLOPT_HEADER => false,
                 CURLOPT_POSTFIELDS => array('field1' => $someval, ...etc)
                );

curl_setopt_array($ch, $options);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now