You can find our user documentation at docs.cpanel.net.

Check out our new API beta site!

Child pages
  • WHM API 1 Functions - cors_proxy_get
Skip to end of metadata
Go to start of metadata

Description

This function allows your system to perform Cross-Origin Resource Sharing (CORS) HTTP requests.

Examples 


 JSON API
https://hostname.example.com:2087/cpsess##########/json-api/cors_proxy_get?api.version=1&url=http%3A%2F%2Fwww.example.com
 Command Line
whmapi1 cors_proxy_get url=http%3A%2F%2Fwww.example.com


Notes:

  • Unless otherwise noted, you must URI-encode values.
  • For more information and additional output options, read our Guide to WHM API 1 documentation or run the whmapi1 --help command.
  • If you run CloudLinux™, you must use the full path of the whmapi1 command:

    /usr/local/cpanel/bin/whmapi1

 Output (JSON)
{
   "data":{
      "status":"200",
      "_cp_redirects":null,
      "protocol":"HTTP/1.1",
      "headers":{
         "age":"425879",
         "etag":"\"3147526947+ident\"",
         "server":"ECS (dab/4BA8)",
         "vary":"Accept-Encoding",
         "expires":"Thu, 12 Mar 2020 23:42:25 GMT",
         "content-length":"1256",
         "cache-control":"max-age=604800",
         "last-modified":"Thu, 17 Oct 2019 07:18:26 GMT",
         "content-type":"text/html; charset=UTF-8",
         "date":"Thu, 05 Mar 2020 23:42:25 GMT",
         "x-cache":"HIT"
      },
      "url":"http://www.example.com",
      "content":"<!doctype html>\n<html>\n<head>\n    <title>Example Domain</title>\n\n    <meta charset=\"utf-8\" />\n    <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <style type=\"text/css\">\n    body {\n        background-color: #f0f0f2;\n        margin: 0;\n        padding: 0;\n        font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n        \n    }\n    div {\n        width: 600px;\n        margin: 5em auto;\n        padding: 2em;\n        background-color: #fdfdff;\n        border-radius: 0.5em;\n        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n    }\n    a:link, a:visited {\n        color: #38488f;\n        text-decoration: none;\n    }\n    @media (max-width: 700px) {\n        div {\n            margin: 0 auto;\n            width: auto;\n        }\n    }\n    </style>    \n</head>\n\n<body>\n<div>\n    <h1>Example Domain</h1>\n    <p>This domain is for use in illustrative examples in documents. You may use this\n    domain in literature without prior coordination or asking for permission.</p>\n    <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n",
      "reason":"OK",
      "success":"1"
   },
   "metadata":{
      "command":"cors_proxy_get",
      "result":1,
      "version":1,
      "reason":"OK"
   }
}


Note:

Use WHM's API Shell interface (WHM >> Home >> Development >> API Shell) to directly test WHM API calls.

Parameters

ParameterTypeDescriptionPossible valuesExample
urlstring

Required

The website that you wish to access.

A valid URL.

http://www.example.com

Returns

ReturnTypeDescriptionPossible valuesExample
content
string

The URL's content.

Notes:

  • We strongly recommend that you confirm the content's type before you use the content return's value.
  • The function may also return this value in the _cp_redirects array of hashes.

A valid string.

 Click to view...
<!doctype html>\n<html>\n<head>\n    <title>Example Domain</title>\n\n    <meta charset=\"utf-8\" />\n    <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <style type=\"text/css\">\n    body {\n        background-color: #f0f0f2;\n        margin: 0;\n        padding: 0;\n        font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n        \n    }\n    div {\n        width: 600px;\n        margin: 5em auto;\n        padding: 2em;\n        background-color: #fdfdff;\n        border-radius: 0.5em;\n        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n    }\n    a:link, a:visited {\n        color: #38488f;\n        text-decoration: none;\n    }\n    @media (max-width: 700px) {\n        div {\n            margin: 0 auto;\n            width: auto;\n        }\n    }\n    </style>    \n</head>\n\n<body>\n<div>\n    <h1>Example Domain</h1>\n    <p>This domain is for use in illustrative examples in documents. You may use this\n    domain in literature without prior coordination or asking for permission.</p>\n    <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n
_cp_redirects
array of hashes

An array that contains the redirects which the website performs, if any exist.

Notes:

  • This return counts redirects.
  • This return is for internal use only.
  • If redirects exist, an array of hashes that contains the content, protocol, reason, status, success, and url returns and the headers hash.
  • null — Redirects do not exist.

    Note:

    The JSON example output above displays this condition.


reason

string

The response that the server returned.

If redirects exist, the function returns this value in the _cp_redirects array of hashes

A valid string.OK

url

string

The URL that provided the response.

If redirects exist, the function returns this value in the _cp_redirects array of hashes.


A valid URL.http://www.example.com

headers

hash

A hash of the header fields that the request returned.

If redirects exist, the function returns this hash in the _cp_redirects array of hashes.

A hash of valid header fields.

Note:

This hash's returns vary based on the URL's headers.


protocol

string

The URL's HTTP protocol.

If redirects exist, the function returns this value in the _cp_redirects array of hashes.

A valid HTTP protocol.

HTTP/1

success

Boolean

Whether the function returned a 2XX HTTP status code.

If redirects exist, the function returns this value in the _cp_redirects array of hashes.

  • 1 — Success.
  • 0 — Failure.


1

status

string

The response's HTTP status code.

If redirects exist, the function returns this value in the _cp_redirects array of hashes.

A valid HTTP status code.200