🖥️Get Website Headers
Gets the response headers of a website.
The API host for all tools is tools.datalabs.net.
Website Status API
POST https://tools.datalabs.net/getHeaders
Host: tools.datalabs.net
Content-Type: application/json
{
"key": "DATALABS_API_KEY", // Required - DataLabs API Key
"host": "example.com" // Required - Host to be checked
}
import requests
api_key = "DATALABS_API_KEY"
tool = "getHeaders"
host = "example.com"
url = f"https://tools.datalabs.net/{tool}?key={api_key}&host={host}"
headers = {
'Host': 'tools.datalabs.net'
}
response = requests.get(url, headers=headers)
try:
response_data = response.json()
except ValueError:
response_data = response.text
print(response_data)
const axios = require('axios');
const api_key = "DATALABS_API_KEY";
const tool = "getHeaders";
const host = "example.com";
const url = `https://tools.datalabs.net/${tool}?key=${api_key}&host=${host}`;
const headers = {
'Host': 'tools.datalabs.net'
};
axios.get(url, { headers })
.then(response => {
console.log(response.data);
})
.catch(error => {
if (error.response) {
console.log(error.response.data);
} else {
console.log(error.message);
}
});
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
apiKey := "DATALABS_API_KEY"
tool := "getHeaders"
host := "example.com"
url := fmt.Sprintf("https://tools.datalabs.net/%s?key=%s&host=%s", tool, apiKey, host)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Println("Error:", err)
return
}
req.Header.Set("Host", "tools.datalabs.net")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error making HTTP request:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Printf("Non-OK HTTP status: %s\n", resp.Status)
return
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
var responseData map[string]interface{}
if err := json.Unmarshal(body, &responseData); err != nil {
fmt.Println("Error unmarshaling JSON:", err)
fmt.Println(string(body))
} else {
fmt.Println(responseData)
}
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json; // Ensure this directive is present for JsonReaderException
class Program
{
static void Main(string[] args)
{
// Call the async method
MainAsync(args).GetAwaiter().GetResult();
}
static async Task MainAsync(string[] args)
{
string apiKey = "DATALABS_API_KEY";
string tool = "getHeaders";
string host = "example.com";
string url = string.Format("https://tools.datalabs.net/{0}?key={1}&host={2}", tool, apiKey, host);
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Host", "tools.datalabs.net");
try
{
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
try
{
var responseData = JObject.Parse(responseBody);
Console.WriteLine("Response data:");
Console.WriteLine(responseData);
}
catch (JsonReaderException jsonEx)
{
Console.WriteLine("JSON Parsing error: " + jsonEx.Message);
Console.WriteLine("Response body:");
Console.WriteLine(responseBody);
}
}
catch (HttpRequestException e)
{
Console.WriteLine("Request error: " + e.Message);
}
}
}
}
Example Response
{
"success": true,
"result": "HTTP/1.1 200 OK<br>\r\nAccept-Ranges: bytes<br>\r\nAge: 147103<br>\r\nCache-Control: max-age=604800<br>\r\nContent-Type: text/html; charset=UTF-8<br>\r\nDate: Fri, 07 Jun 2024 02:57:21 GMT<br>\r\nEtag: \"3147526947\"<br>\r\nExpires: Fri, 14 Jun 2024 02:57:21 GMT<br>\r\nLast-Modified: Thu, 17 Oct 2019 07:18:26 GMT<br>\r\nServer: ECAcc (chd/0796)<br>\r\nX-Cache: HIT<br>\r\nContent-Length: 1256<br>\r\n<br>\r\n",
"splitted_result": [
"HTTP/1.1 200 OK",
"\r\nAccept-Ranges: bytes",
"\r\nAge: 147103",
"\r\nCache-Control: max-age=604800",
"\r\nContent-Type: text/html; charset=UTF-8",
"\r\nDate: Fri, 07 Jun 2024 02:57:21 GMT",
"\r\nEtag: \"3147526947\"",
"\r\nExpires: Fri, 14 Jun 2024 02:57:21 GMT",
"\r\nLast-Modified: Thu, 17 Oct 2019 07:18:26 GMT",
"\r\nServer: ECAcc (chd/0796)",
"\r\nX-Cache: HIT",
"\r\nContent-Length: 1256",
"\r\n",
"\r\n"
]
}
Last updated