{"id":124,"date":"2009-07-02T11:12:54","date_gmt":"2009-07-02T15:12:54","guid":{"rendered":"http:\/\/www.dev-notes.com\/blog\/2009\/07\/02\/shorten-long-urls-with-perl-curl-and-the-short-to-api\/"},"modified":"2009-07-02T11:12:54","modified_gmt":"2009-07-02T15:12:54","slug":"shorten-long-urls-with-perl-curl-and-the-short-to-api","status":"publish","type":"post","link":"https:\/\/www.dev-notes.com\/blog\/2009\/07\/02\/shorten-long-urls-with-perl-curl-and-the-short-to-api\/","title":{"rendered":"Shorten long URLs with Perl, cURL, and the short.to API"},"content":{"rendered":"<pre class=\"code\">\n#!\/usr\/bin\/perl\n\n### This is the long URL we wish to ultimately shorten\n$url = \"http:\/\/ww2db.com\/battle_spec.php?battle_id=10\";\n\n\n\nsub body_callback {\n        my ($chunk,$context)=@_;\n        push @{$context}, $chunk;\n        return length($chunk);\n}\n\nuse Curl::easy;\n\nmy $curl= Curl::easy::init();\nCurl::easy::setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);\nCurl::easy::setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);\nCurl::easy::setopt ($curl, CURLOPT_URL, \"http:\/\/short.to\/s.txt?url=$url\");\nCurl::easy::setopt ($curl, CURLOPT_WRITEFUNCTION, &body_callback);\nmy @body;\nCurl::easy::setopt ($curl, CURLOPT_FILE, @body);\nCurl::easy::setopt ($curl, CURLOPT_ERRORBUFFER, \"errorBuffer\");\n\nif (Curl::easy::perform ($curl) != 0) {\n\tprint \"Fail: $errorBuffern\";\n}\nelse {\n\t### Now we have the URL stored within @body for our use.\n\tprint \"Success: @bodyn\";\n};\n\nCurl::easy::cleanup($curl);\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This sample Perl script illustrates how to use the cURL::Easy extension of libcurl to use short.to&#8217;s API to shorten long URLs.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-124","post","type-post","status-publish","format-standard","hentry","category-perl"],"_links":{"self":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/comments?post=124"}],"version-history":[{"count":0,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/124\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/categories?post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/tags?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}