Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 31 lines (29 sloc) 1.287 kB
3578c08 Added PHP template
David Barton authored
1 <section name="php" class="php">
b62198c @zdne 'In' (input) renamed 'to' Request
zdne authored
2 <p class="ioDesc">Request</p>
3e55cb0 @kuba-kubula Support new lines under ECTjs
kuba-kubula authored
3 <pre class="incoming"><code class="language-php"><% headerFirst = true %><%= "<?php\n" %>
2f39de6 @tu1ly fix for multiline body
tu1ly authored
4 <% eos = "<<<EOT\n" %>
3578c08 Added PHP template
David Barton authored
5 $ch = curl_init();
6 curl_setopt($ch, CURLOPT_URL, "<%= @apiUrl %><%= @url %>");
7 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
290d82f Added php end tag and disabled php header output
David Barton authored
8 curl_setopt($ch, CURLOPT_HEADER, FALSE);
3637277 @kuba-kubula PRE with CODE element with class language
kuba-kubula authored
9 <% if @method is 'POST': %>
10 curl_setopt($ch, CURLOPT_POST, TRUE);
3e55cb0 @kuba-kubula Support new lines under ECTjs
kuba-kubula authored
11 <% end %>
025ea90 @zdne PHP and curl HEAD HTTP method support origin
zdne authored
12 <% if @method is 'HEAD': %>
13 curl_setopt($ch, CURLOPT_NOBODY, TRUE);
14 <% end %>
3e55cb0 @kuba-kubula Support new lines under ECTjs
kuba-kubula authored
15 <% if @method isnt 'GET' and @method isnt 'POST': %>
3637277 @kuba-kubula PRE with CODE element with class language
kuba-kubula authored
16 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "<%= @method %>");
3e55cb0 @kuba-kubula Support new lines under ECTjs
kuba-kubula authored
17 <% end %>
18 <% if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %>
24a4af1 @kuba-kubula Hardening templates for missing @body
kuba-kubula authored
19 $fields = <%= eos %><%= @body or '' %>EOT;
3e55cb0 @kuba-kubula Support new lines under ECTjs
kuba-kubula authored
20 curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
21 <% else if @body and @body.length > 0: %>
22 curl_setopt($ch, CURLOPT_POSTFIELDS, <%= @helpers.escape @body %>);
23 <% end %>
2f39de6 @tu1ly fix for multiline body
tu1ly authored
24 <% if @headers and @helpers.isNotEmpty(@headers): %>curl_setopt($ch, CURLOPT_HTTPHEADER, array(<% for header, value of @headers: %><% if headerFirst: %><% headerFirst = false %><% else: %>, <% end %><%= @helpers.escape "#{header}: #{value}" %><% end %>));
3e55cb0 @kuba-kubula Support new lines under ECTjs
kuba-kubula authored
25 <% end %>
26 $response = curl_exec($ch);
3578c08 Added PHP template
David Barton authored
27 curl_close($ch);
28
5ba7040 @kuba-kubula php snippet is better without closing lines
kuba-kubula authored
29 var_dump($response);</code></pre>
3578c08 Added PHP template
David Barton authored
30 </section>
Something went wrong with that request. Please try again.