Scodigo, Inc.

Log In | Register

Cart Items:
0

Http POST sample code (required)

Hi
Can somebody please help me with sample code to do a simple http post with SmartPill using 2 fields - 'url' and 'data' in filemaker 8.5 windows/Mac
I am using the sample get/ftp which works
Zero php knowledge !
Many thanks

Http POST sample code (required)

Micah Woods's picture

Hello Nigel,

Included with the SmartPill download, you should find a file named "SmartPill PHP Examples 2" which includes an example titled "Translation". This example posts data to a website that does translation and then reads the results. I'd suggest taking a look at this example and you'll also find good info in the PHP online manual here: http://us2.php.net/curl.

I've also put together a simple snippet of code that should allow you to post a single data field. I didn't have a chance to test it but it should work.

// the data you want to post
$my_data = 'hello world';

// the name of the field you want to use
$my_field = 'some_data';

// the url you want to post to
$url = 'http://www.example.com';

// build the curl post array
$post_data = array();
$post_data[$my_field] = $my_data;

// use curl to post our request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$post_result = curl_exec($ch);

if (curl_errno($ch)) {
print curl_error($ch);
}

curl_close($ch);

print($post_result);

Hope this helps to get you going.

Regards,
Micah

Http POST sample code - thanks

Thanks Micah
This will get started - I will post when I get it going
Cheers
Nigel