Code Examples
Here are examples of how to test HTTP 301 responses in different programming languages:
Select options below to see how to use advanced features in your code:
curl https://free.mockerapi.com/301
{ "success": true, "status": 301, "statusText": "Moved Permanently - The URL of the requested resource has been changed permanently", "timestamp": "2025-10-08T10:30:45.123Z", "request": { "method": "GET", "url": "/301", "fullUrl": "https://free.mockerapi.com/301" } }
fetch('https://free.mockerapi.com/301') .then(response => { console.log('Status:', response.status); // 301 return response.json(); }) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); });
{ "success": true, "status": 301, "statusText": "Moved Permanently - The URL of the requested resource has been changed permanently", "timestamp": "2025-10-08T10:30:45.123Z", "request": { "method": "GET", "url": "/301", "fullUrl": "https://free.mockerapi.com/301" } }
import requests response = requests.get('https://free.mockerapi.com/301') print(f'Status Code: {response.status_code}') # 301 print(f'Response: {response.json()}')
{ "success": true, "status": 301, "statusText": "Moved Permanently - The URL of the requested resource has been changed permanently", "timestamp": "2025-10-08T10:30:45.123Z", "request": { "method": "GET", "url": "/301", "fullUrl": "https://free.mockerapi.com/301" } }
{ "success": true, "status": 301, "statusText": "Moved Permanently - The URL of the requested resource has been changed permanently", "timestamp": "2025-10-08T10:30:45.123Z", "request": { "method": "GET", "url": "/301", "fullUrl": "https://free.mockerapi.com/301" } }
require 'net/http' require 'json' uri = URI('https://free.mockerapi.com/301') response = Net::HTTP.get_response(uri) puts "Status Code: #{response.code}" # 301 puts "Response: #{JSON.parse(response.body)}"
{ "success": true, "status": 301, "statusText": "Moved Permanently - The URL of the requested resource has been changed permanently", "timestamp": "2025-10-08T10:30:45.123Z", "request": { "method": "GET", "url": "/301", "fullUrl": "https://free.mockerapi.com/301" } }
package main import ( "fmt" "io" "net/http" ) func main() { resp, err := http.Get("https://free.mockerapi.com/301") if err != nil { panic(err) } defer resp.Body.Close() fmt.Printf("Status Code: %d\n", resp.StatusCode) // 301 body, err := io.ReadAll(resp.Body) if err != nil { panic(err) } fmt.Printf("Response: %s\n", body) }
{ "success": true, "status": 301, "statusText": "Moved Permanently - The URL of the requested resource has been changed permanently", "timestamp": "2025-10-08T10:30:45.123Z", "request": { "method": "GET", "url": "/301", "fullUrl": "https://free.mockerapi.com/301" } }
import java.net.http.*; import java.net.URI; public class HttpStatusTest { public static void main(String[] args) throws Exception { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://free.mockerapi.com/301")) .GET() .build(); HttpResponseresponse = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println("Status Code: " + response.statusCode()); // 301 System.out.println("Response: " + response.body()); } }
{ "success": true, "status": 301, "statusText": "Moved Permanently - The URL of the requested resource has been changed permanently", "timestamp": "2025-10-08T10:30:45.123Z", "request": { "method": "GET", "url": "/301", "fullUrl": "https://free.mockerapi.com/301" } }
const https = require('https'); https.get('https://free.mockerapi.com/301', (res) => { console.log('Status Code:', res.statusCode); // 301 let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log('Response:', JSON.parse(data)); }); }).on('error', (err) => { console.error('Error:', err.message); });
{ "success": true, "status": 301, "statusText": "Moved Permanently - The URL of the requested resource has been changed permanently", "timestamp": "2025-10-08T10:30:45.123Z", "request": { "method": "GET", "url": "/301", "fullUrl": "https://free.mockerapi.com/301" } }
What is HTTP 301 Moved Permanently?
HTTP 301 Moved Permanently indicates that the requested resource has been permanently moved to a new URL. This status code tells clients and search engines that the resource should be requested from the new location in all future requests.
The server should include a Location header in the response indicating the new permanent URI. Browsers and clients typically automatically redirect to the new location, and search engines transfer the SEO value from the old URL to the new one.
When Does This Happen?
A 301 Moved Permanently response is returned when:
- A page has permanently moved to a new URL (e.g., site restructuring)
- Migrating from HTTP to HTTPS for a website
- Consolidating multiple pages into a single page
- Changing domain names while preserving SEO rankings
- Implementing URL canonicalization (e.g., www to non-www)
Try It Live
Click the button below to make a live request and see the 301 Moved Permanently response
Common Use Cases
๐ Redirect Testing
Test how your application handles permanent redirects and updates cached URLs appropriately.
๐ HTTPS Migration
Mock and test HTTPS migration scenarios where HTTP URLs permanently redirect to HTTPS.
๐ SEO Testing
Test SEO tools and crawlers to ensure they properly handle permanent redirects and URL changes.
๐ Domain Migration
Test client behavior during domain migrations where old URLs redirect to new domains.
๐ฑ Link Preservation
Verify that applications properly follow redirects to maintain functionality when URLs change.
๐งช Client Behavior
Test how different HTTP clients handle Location headers and automatic redirect following.