Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
5 total  XML / RSS feed 

using curl

using curl to set content-type and post

curl -i -X POST -H "Content-Type: application/xml" -d @example.xml http://localhost:3000/example.xml

using curl to set Accept header

curl -i -H "Accept: application/xml" http://localhost:3000/example.xml

Facebook Status Updater using cURL

*       Facebook Status Updater
*       Christian Flickinger
*    April 20, 2007

$status = 'YOUR_STATUS';
$first_name = 'YOUR_FIRST_NAME';
$login_email = 'YOUR_LOGIN_EMAIL';
$login_pass = 'YOUR_PASSWORD';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ';');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070309 Firefox/");

curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, '');
$page = curl_exec($ch);

curl_setopt($ch, CURLOPT_POST, 1);
preg_match('/name="post_form_id" value="(.*)" \/>'.ucfirst($first_name).'/', $page, $form_id);
curl_setopt($ch, CURLOPT_POSTFIELDS,'post_form_id='.$form_id[1].'&status='.urlencode($status).'&update=Update');
curl_setopt($ch, CURLOPT_URL, '');

cURL Response Times

Determine response times of a URL with cURL.

echo "`curl -s -o /dev/null -w '%{time_starttransfer}-%{time_pretransfer}'`"|bc

curl -w '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' -o /dev/null -s

Downloading large files with cURL

man curl

# broken downloads will be resumed automatically
cd ~/Desktop; while ! curl -C - -O ''; do sleep 10; done

# requires FTP to be enabled in your firewall configuration
cd ~/Desktop; while ! curl -L -C - -O ''; do sleep 10; done

Source: Download with cURL in a Loop Until Completed

Upload all .gif and .jpg files in a directory to textpattern

This will upload all files in the current directory ending in jpg jpeg or gif through your textpattern-admin panel to your site.

Save this as a shell script, adjust the first 3 variables and excute. (Note: LOGIN and PASS should be ascii only, or else manually url-encoded)


COOKIE=$(curl -s -D - -d "p_userid=$LOGIN&p_password=$PASS" \
    $URL | head -n10 | sed -n 's/^Set\-Cookie\: //p')

if [ -z $COOKIE ] 
  echo "Can't log in."
  exit 1
  echo "Cookie: "$COOKIE

for file in $(ls -1|egrep '(gif)|(jpe?g)$') ; 
 echo "Sending "$file
 curl -s -H "Cookie: $COOKIE" -F "thefile=@$file" \
   -F "event=image" -F "step=image_insert" $URL > /dev/null

This will not output anything. But after it returns to the prompt, log in to textpattern and take a look into the image section.

Update: Added rudimentary check wether login is successful and basic progress meter.
« Newer Snippets
Older Snippets »
5 total  XML / RSS feed