Note that there are some explanatory texts on larger screens.

plurals
  1. POHow I will write this curl request
    primarykey
    data
    text
    <p>Hello There I am working with an API. In API documentation it is clearly written that aAll data is sent and received as JSON, with an UTF-­8 encoding. And after that they gave one line</p> <pre><code>$ curl -­-­user name:password https://api.abc.de/erer </code></pre> <p>I just want to ask how I will send curl request as they mentioned above? The username and password will be sent as <code>GET</code>, <code>POST</code> or in <code>headers</code>? </p> <p>I am using following code but receiving empty array. The documentation says it must receive some error or success code.</p> <pre><code>$ch = curl_init(); $post_data = array('username'=&gt;$_POST['username'],'password'=&gt;$_POST['password']); $post_data = http_build_query($post_data); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, 'username:password'); $result = curl_exec($ch); curl_close($ch); $result = json_decode($result); $result = (array) $result; echo "&lt;pre&gt;"; print_r($result); echo "&lt;/pre&gt;"; die(); </code></pre> <p>I have printed out response of <code>curl_get_info</code> that is</p> <pre><code>Array ( [url] =&gt; https://api.abc.de/erer [content_type] =&gt; [http_code] =&gt; 0 [header_size] =&gt; 0 [request_size] =&gt; 0 [filetime] =&gt; -1 [ssl_verify_result] =&gt; 0 [redirect_count] =&gt; 0 [total_time] =&gt; 0 [namelookup_time] =&gt; 0.618462 [connect_time] =&gt; 0 [pretransfer_time] =&gt; 0 [size_upload] =&gt; 0 [size_download] =&gt; 0 [speed_download] =&gt; 0 [speed_upload] =&gt; 0 [download_content_length] =&gt; 0 [upload_content_length] =&gt; 0 [starttransfer_time] =&gt; 0 [redirect_time] =&gt; 0 ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload