title: How do I properly encode values that I send to PayPal Payments Pro?
body: <h2>Question</h2>
  
  <p>What's the correct way to send parameter lists to the PayPal APIs? Here's a concrete example of some parameters I'd like to know how to send correctly:</p>
  
  <pre><code>TRXTYPE               S
  BILLTOSTREET          123 Marks &amp; Spencer St.
  CUSTREF               648=ZVC_Gxk
  </code></pre>
  
  <p>There is inconsistent documentation on the matter, and most code I've found on the web doesn't use the length-prefixing that PayPal describes (yet still seems to work!). </p>
  
  <h2>Background</h2>
  
  <p>The <a href="https://cms.paypal.com/cms_content/US/en_US/files/developer/PayflowGateway_Guide.pdf" rel="nofollow">PayPal Payments Pro</a> documentation describes their custom and non-standards compliant NVP format on p44 and surrounding pages. It is also contradictorily described on the <a href="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&amp;content_ID=developer/e_howto_api_nvp_NVPAPIOverview" rel="nofollow">PayPal API NVP Basics</a> page  as "All requests to execute PayPal API operations sent using HTTP must be URL-encoded.".</p>
  
  <p>The large PDF doc also contradicts itself:</p>
  
  <ul>
  <li><p>The "Name-Value Parameter Syntax Guidelines" section of the PDF states "Do not use spaces in values". However, it then presents an example of a "correct" NVP string that includes spaces in the BILLTOSTREET parameter.</p></li>
  <li><p>The "Name-Value Parameter Syntax Guidelines" section states "Enclose the NVP parameter string in quotation marks". Is this referring to the entire string of encoded values? Should my POST body look like the following, including quotes?  "TRXTYPE=S&amp;TENDER=C..."</p></li>
  <li><p>It claims that the entire parameter string should be surrounded with double quotes.</p></li>
  </ul>