Felix Riesterer: fetch liefert leeren string

Beitrag lesen

Fortsetzung...

Wenn ich den Content-Type der Response wissen will, steht da null drinnen:

// aus einer function mit async
try {
	const response = await fetch(
		"https://wiki-test.selfhtml.org/extensions/Selfhtml/example.php/Beispiel:HTML-Einstieg-1.txt",
		{ method: "GET", mode: "no-cors" }
	);

	const contentType = response.headers.get("content-type");
console.log("content-type",contentType);  // null
	const text = await response.text();
console.log("text",text); // <empty string>
	this.container = linkElement.parentNode.parentNode.insertBefore(
		document.createElement("div"),
		linkElement.parentNode.nextSibling
	);

} catch (error) {
	console.log(error); // feuert nicht
}

Hatte jemand schon einmal dieses Problem? Hat es mit dem CORS-Dingens zu tun? Denn im Netzwerk-Tab steht die Antwort inklusive aller Header:

GET
	
scheme
	https
host
	wiki-test.selfhtml.org
filename
	/extensions/Selfhtml/example.php/Beispiel:HTML-Einstieg-1.txt
Adresse
	89.238.67.49:443
Status
200
OK
VersionHTTP/1.1
Übertragen806 B (812 B Größe)
Referrer Policystrict-origin-when-cross-origin
DNS-AuflösungSystem

	
Connection
	Keep-Alive
Content-Encoding
	gzip
Content-Length
	511
Content-Type
	text/plain; charset=utf-8
Date
	Sat, 20 Apr 2024 10:42:27 GMT
Keep-Alive
	timeout=5, max=50
Server
	Apache
Vary
	Accept-Encoding
X-Content-Type-Options
	nosniff
X-Powered-By
	PHP/7.0.33
	
Accept
	*/*
Accept-Encoding
	gzip, deflate, br
Accept-Language
	de,en-US;q=0.7,en;q=0.3
Cache-Control
	no-cache
Connection
	keep-alive
DNT
	1
Host
	wiki-test.selfhtml.org
Pragma
	no-cache
Referer
	http://felix.localhost/
Sec-Fetch-Dest
	empty
Sec-Fetch-Mode
	no-cors
Sec-Fetch-Site
	cross-site
User-Agent
	Mozilla/5.0 (X11; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0

Liebe Grüße

Felix Riesterer