<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[response - All your code are belong to us]]></title><description><![CDATA[Thoughts, stories and ideas on code and technology in general.<br>Blog title inspired by <a href="https://en.wikipedia.org/wiki/All_your_base_are_belong_to_us" target="_blank">this meme</a>]]></description><link>https://allurcode.com/</link><image><url>https://allurcode.com/favicon.png</url><title>response - All your code are belong to us</title><link>https://allurcode.com/</link></image><generator>Ghost 4.48</generator><lastBuildDate>Wed, 10 Jun 2026 00:34:28 GMT</lastBuildDate><atom:link href="https://allurcode.com/tag/response/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Handling responses from PHP's cURL]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Recently I had a small problem with cURL. The request was supposed to return only JSON data to use in my app. I wrote the following:</p>
<pre><code class="language-php">$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, &apos;http://somedomain.com/api/123&apos;);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl,</code></pre>]]></description><link>https://allurcode.com/handling-responses-from-phps-curl/</link><guid isPermaLink="false">5b7b0aa2b52b43084c9ea11f</guid><category><![CDATA[cURL]]></category><category><![CDATA[PHP]]></category><category><![CDATA[response]]></category><dc:creator><![CDATA[Wojtek]]></dc:creator><pubDate>Wed, 14 Apr 2010 22:38:56 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>Recently I had a small problem with cURL. The request was supposed to return only JSON data to use in my app. I wrote the following:</p>
<pre><code class="language-php">$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, &apos;http://somedomain.com/api/123&apos;);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_exec($curl);
$status = curl_getinfo($curl);
curl_close($curl);
</code></pre>
<p>The variable <code>$status</code> contained the API&#x2019;s response in plain text and concatenated, inaccessible in this format, array with cURL&#x2019;s status response. This made it impossible to check if the request was successful. I had to get rid of the JSON response and leave only cURL status array. In order to do that I added <code>curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);</code> option which cleared all this garbage and left only cURL&#x2019;s status array.</p>
<pre><code class="language-php">$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, &apos;http://somedomain.com/api/123&apos;);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_exec($curl);
$status = curl_getinfo($curl);
curl_close($curl);
</code></pre>
<p>Last thing I had to do was retrieve API&#x2019;s JSON response and assign it to another variable. I have to say the solution wasn&#x2019;t my first logical choice. After some time it turned out that <code>curl_exec()</code> returns exactly what I need.<br>
In the end, my code became something like this:</p>
<pre><code class="language-php">$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, &apos;http://somedomain.com/api/123&apos;);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$response = curl_exec($curl);
$status = curl_getinfo($curl);
curl_close($curl);
</code></pre>
<p>Now, variable <code>$response</code> contained only JSON and <code>$status</code> contained only cURL&#x2019;s response status. I was happy again.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item></channel></rss>