<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Matthew Turland &#187; .NET</title> <atom:link href="http://matthewturland.com/tag/dotnet/feed/" rel="self" type="application/rss+xml" /><link>http://matthewturland.com</link> <description></description> <lastBuildDate>Tue, 15 May 2012 02:29:07 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Gotcha on Scraping .NET Applications with PHP and cURL</title><link>http://matthewturland.com/2010/06/30/gotcha-on-scraping-net-applications-with-php-and-curl/</link> <comments>http://matthewturland.com/2010/06/30/gotcha-on-scraping-net-applications-with-php-and-curl/#comments</comments> <pubDate>Thu, 01 Jul 2010 02:27:09 +0000</pubDate> <dc:creator>Matthew Turland</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[.NET]]></category> <category><![CDATA[cURL]]></category> <category><![CDATA[Web Scraping]]></category><guid
isPermaLink="false">http://matthewturland.com/?p=365</guid> <description><![CDATA[Obligatory pitch: Many other useful tidbits like this can be yours by purchasing my book, php&#124;architect&#8217;s Guide to Web Scraping with PHP. I recently wrote a PHP script to scrape data from a .NET application. In the process of developing this script, I noticed something interesting that I thought I&#8217;d share. In this case, I [...]]]></description> <content:encoded><![CDATA[<p><em>Obligatory pitch: Many other useful tidbits like this can be yours by purchasing my book, </em><a
title="php|architect&amp;#8217;s Guide to Web Scraping with PHP | php|architect" href="http://www.phparch.com/books/phparchitects-guide-to-web-scraping-with-php/"><em>php|architect&#8217;s Guide to Web Scraping with PHP</em></a><em>.</em></p><p>I recently wrote a PHP script to scrape data from a .NET application. In the process of developing this script, I noticed something interesting that I thought I&#8217;d share. In this case, I was using the <a
title="PHP: cURL - Manual" href="http://php.net/manual/en/book.curl.php">cURL extension</a>, but the tip isn&#8217;t necessarily specific to that. One thing my script did was submit a <a
title="POST (HTTP) - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/POST_(HTTP)">POST request</a> to simulate a form submission. The code looked something like the sample below.</p><pre class="brush: php; title: ; notranslate">$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL =&gt; 'http://...',
    CURLOPT_POST =&gt; true,
    CURLOPT_POSTFIELDS =&gt; array(
        'field1' =&gt; 'value1',
        // ...
    ),
    // ...
));</pre><p>The issue I ran into had to do with a behavior of the <code>CURLOPT_POSTFIELDS</code> setting that&#8217;s easy to overlook. This is a segment of its description from the <a
title="PHP: curl_setopt - Manual" href="http://us3.php.net/curl_setopt">PHP manual page</a> for the <code>curl_setopt()</code> function.</p><blockquote><p>If <em>value</em> is an array, the <em>Content-Type</em> header will be set to <em>multipart/form-data</em>.</p></blockquote><p>If the form being submitted is not set to have an <code>enctype</code> attribute value of <code>multipart/form-data</code> in the form&#8217;s markup, .NET returns a 500-level HTTP response with no further information on what causes the error (for security purposes). This presumably happens because it&#8217;s expecting one value for the <code>Content-Type</code> request header and getting another.</p><p>Setting <code>CURLOPT_HEADER</code> and <code>CURLOPT_VERBOSE</code> to <code>true</code> helped to reveal that this was the issue. The fix is pretty simple: instead of passing the array itself for <code>CURLOPT_POSTFIELDS</code>, pass the result of wrapping it in a call to the  <code>http_build_query()</code> function (see its <a
title="PHP: http_build_query - Manual" href="http://us.php.net/http_build_query">PHP manual page</a>). This converts it to a properly formatted query string, which causes cURL to use the default <code>Content-Type</code> header value of <code>application/x-www-form-urlencoded</code> instead.</p><p>Tools like <a
title="Firebug" href="http://getfirebug.com">Firebug</a> can help you to examine requests made by a browser. Together with these settings for cURL, you can modify your script&#8217;s requests to match those of your browser as closely as possible, making gotchas like this less likely to trip you up.</p> ]]></content:encoded> <wfw:commentRss>http://matthewturland.com/2010/06/30/gotcha-on-scraping-net-applications-with-php-and-curl/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>The Yin and Yang of Typing</title><link>http://matthewturland.com/2008/01/20/the-yin-and-yang-of-typing/</link> <comments>http://matthewturland.com/2008/01/20/the-yin-and-yang-of-typing/#comments</comments> <pubDate>Sun, 20 Jan 2008 04:33:53 +0000</pubDate> <dc:creator>Matthew Turland</dc:creator> <category><![CDATA[Uncategorized]]></category> <category><![CDATA[.NET]]></category> <category><![CDATA[C]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[PL/SQL]]></category> <category><![CDATA[Programming Languages]]></category><guid
isPermaLink="false">http://ishouldbecoding.com/2008/01/19/the-yin-and-yang-of-typing/</guid> <description><![CDATA[Without a little background in programming languages or computer science in general, it&#8217;s entirely possible that typing systems are not something that have crossed your mind. I thought I&#8217;d take a blog entry to share some of my thoughts on how it&#8217;s affecting the creation and evolution of languages. First of all, Benjamin C. Pierce [...]]]></description> <content:encoded><![CDATA[<p>Without a little background in programming languages or computer science in general, it&#8217;s entirely possible that <a
title="Type system - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Type_system">typing systems</a> are not something that have crossed your mind. I thought I&#8217;d take a blog entry to share some of my thoughts on how it&#8217;s affecting the creation and evolution of languages.</p><p>First of all, <a
title="Benjamin C. Pierce - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Benjamin_C._Pierce">Benjamin C. Pierce</a> probably has <a
title="Strongly-typed programming language - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Strong_typing#Interpretation">a point</a>: terminology used to refer to typing concepts is about as useful as buzzwords like <a
title="Ajax (programming) - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Ajax_%28programming%29">AJAX</a> or <a
title="Web 2.0 - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Web_2.0#Defining_.22Web_2.0.22">Web 2.0</a> these days. Be that as it may, I&#8217;m going to reach back into the recesses of what I recall from the <a
title="CMPS 450: Programming Languages" href="http://louisiana.edu/Academic/Sciences/CMPS/curriculum/crsdesc/450.pdf">programming languages course</a> I took in college to recall some of this terminology.</p><p>If you aren&#8217;t familiar with <a
title="Type system - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Static_typing#Static_typing">static</a> versus <a
title="Type system - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing">dynamic</a> typing or <a
title="Strongly-typed programming language - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Strong_typing">strong</a> versus <a
title="Weak typing - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Weak_typing">weak</a> typing, it may be worth it to read up on those before proceeding with the rest of this blog entry. Here are a few examples of each:</p><ul><li>Static/weak &#8211; <a
title="C (programming language) - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/C_programming_language">C</a></li><li>Static/strong &#8211; <a
title="Java (programming language) - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Java_programming_language">Java</a></li><li>Dynamic/weak &#8211; <a
title="PHP - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/PHP">PHP </a></li><li>Dynamic/strong &#8211; <a
title="Python (programming language) - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Python_programming_language">Python</a></li></ul><p>The line between strong versus weak typing seems to be blurred as languages like these evolve. The reason for this is that each side of typing has its advantages. Strong typing allows for compile-time checking, which can serve to eliminate human error, as well as performance optimizations from being aware of types at compile-time. They can also serve to make source code more intuitive to follow in some respects. Weak typing, on the other hand, can allow for higher levels of abstraction and, by proxy, the need for less code in order to allow identical operations to be executed on multiple types. It can also allow for things like <a
title="PHP: Variable variables - Manual" href="http://www.php.net/manual/en/language.variables.variable.php">variable variables</a>, <a
title="PHP: Variable functions - Manual" href="http://www.php.net/manual/en/functions.variable-functions.php">variable functions</a>, and other interesting features not possible in strongly-typed languages.</p><p>Yet languages on either side of the proverbial fence are drawing in strengths from the other side. Java, before limited to the flexibility that could be provided by <a
title="Polymorphism (computer science) - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29">polymorphism</a> while still maintaining strong typing, introduced <a
title="Generics" href="http://docs.oracle.com/javase/1.5.0/docs/guide/language/generics.html">generics</a> in 1.5, whereby typing was still enforced but a higher level of logic abstraction was enabled for developers. By the same token, PHP has had explicit <a
title="PHP: Type Juggling - Manual" href="http://www.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting">typecasting</a> for a while and more recently in 5.1 introduced <a
title="PHP: Type Hinting - Manual" href="http://www.php.net/manual/en/language.oop5.typehinting.php">type hinting</a> for array and object types (which may extend to scalar types in later versions). C# in 3.5 adds <a
title="Type inference != Dynamic typing - the blog =&lt; anything goes" href="http://msmvps.com/blogs/senthil/archive/2007/11/19/type-inference-dynamic-typing.aspx">type inferencing</a>, which while it&#8217;s only syntactic sugar at least alleviates the need for verbosity when performing the most common method of initialization (i.e. setting a variable of a given class to an object instance of that class, as opposed to one involving a subclass of one or more of the classes involved).</p><p>It&#8217;s also becoming commonplace for dynamically typed language interpreters to get ported to Java and .NET in order to leverage the features of those languages and the native libraries of the host language in the existing execution environment. Take these examples for instance.</p><ul><li><a
href="http://quercus.caucho.com/">Quercus</a> (Java) and <a
href="http://php-compiler.net">Phalanger</a> (.NET) for <a
href="http://php.net/">PHP</a></li><li><a
href="http://www.jruby.org/">JRuby</a> (Java) and <a
href="http://www.ironruby.net/">IronRuby</a> (.NET) for <a
href="http://www.ruby-lang.org/en/">Ruby</a></li><li><a
href="http://www.jython.org/">Jython</a> (Java) and <a
href="http://www.codeplex.com/IronPython">IronPython</a> (.NET) for <a
href="http://python.org/">Python</a></li></ul><p>In short, some level of control over typing is obviously a desired feature in any useful language. As well, I don&#8217;t think a language can be truly useful without having a bit of both worlds to some degree. The reason for the existence of programming languages is to enable developers to control machines whose primary purpose is to manipulate data (and, as has been pointed out many times before, are stupid and do what we tell them to do). If control over said manipulation is hampered by the typing system, it hampers the effectiveness of the language. In this, I have to agree with <a
title="Ludwig Wittgenstein - Wikiquote" href="http://en.wikiquote.org/wiki/Ludwig_Wittgenstein">Ludwig Wittgenstein</a>, who said, &#8220;The limits of my language mean the limits of my world.&#8221;</p> ]]></content:encoded> <wfw:commentRss>http://matthewturland.com/2008/01/20/the-yin-and-yang-of-typing/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using apc
Page Caching using disk: enhanced
Database Caching 16/19 queries in 0.008 seconds using apc

Served from: matthewturland.com @ 2012-05-21 17:04:29 -->
