Mecha CMS

Deep learning on using the API.

Class HTTP

Author: Taufik Nurrohman · 80 Views

Tweet

Working with HTTP headers.

Table of Content

Status 

Set HTTP status.

HTTP::status($i = 200);

List of HTTP status code:

CodeDescription
100Continue
101Switching Protocols
102Processing 1
200OK
201Created
202Accepted
203Non-Authoritative Information
204No Content
205Reset Content
206Partial Content
207Multi-Status 2
208Already Reported 3
226IM Used 4
300Multiple Choices
301Moved Permanently
302Found
303See Other
304Not Modified
305Use Proxy
306Reserved
307Temporary Redirect
308Permanent Redirect 5
400Bad Request
401Unauthorized
402Payment Required
403Forbidden
404Not Found
405Method Not Allowed
406Not Acceptable
407Proxy Authentication Required
408Request Timeout
409Conflict
410Gone
411Length Required
412Precondition Failed
413Request Entity Too Large
414Request-URI Too Long
415Unsupported Media Type
416Requested Range Not Satisfiable
417Expectation Failed
418I'm a teapot 6
422Unprocessable Entity 2
423Locked 2
424Failed Dependency 2
425Reserved for WebDAV advanced collections expired proposal 7
426Upgrade Required 7
428Precondition Required 8
429Too Many Requests 8
431Request Header Fields Too Large 8
500Internal Server Error
501Not Implemented
502Bad Gateway
503Service Unavailable
504Gateway Timeout
505HTTP Version Not Supported
506Variant Also Negotiates (Experimental) 9
507Insufficient Storage 2
508Loop Detected 3
510Not Extended 10
511Network Authentication Required' 8

Query 

Add, remove and update the current query string URL keys and values.

HTTP::query($query = [], $c = ['?', '&', '=']);

Example:

// → ?a=b&c=d&e=[f]=g

echo HTTP::query(['c' => 1000]);

Result:

?a=b&c=1000&e=[f]=g

Note: Setting the property value to true will insert a query string without value, setting the property value to the string "true" will insert a query string with value true:

// → ?a=b

echo HTTP::query([
    'c' => true,
    'd' => 'true'
]);

Result:

?a=b&c&d=true

Setting the property value to false will remove the query string, setting the property value to the string "false" will insert a query string with value false:

// → ?a=b

echo HTTP::query([
    'a' => false,
    'c' => 'false'
]);

Result:

?c=false

Header 

Set HTTP headers.

HTTP::header($key, $value = null);

Example:

HTTP::header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
HTTP::header('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT');
HTTP::header([
    'Expires' => 'Sat, 26 Jul 1997 05:00:00 GMT',
    'Cache-Control' => 'no-cache, must-revalidate'
]);

Mime 

Set mime type in HTTP headers.

HTTP::mime($mime, $charset = null);

Example:

HTTP::mime('text/xml');

Post 

HTTP::post($url, $fields = []);

Get 

HTTP::get($url, $fields = []);

  1. RFC2518 

  2. RFC4918 

  3. RFC5842 

  4. RFC3229 

  5. RFC-reschke-http-status-308-07 

  6. RFC2324 

  7. RFC2817 

  8. RFC6585 

  9. RFC2295 

  10. RFC2774 

0 Comments

No comments yet.