encoding ISO-8859-1 to UTF-8 in std.net.curl

Alexsej via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 8 12:57:54 PDT 2016


import std.stdio;
import std.net.curl;

void main()
{

	string url = "www.site.ru/xml/api.asp";

	string data =
	"<?xml version='1.0' encoding='UTF-8'?>
		<request>
		<category>
			<id>59538</id>
		</category>
                 ...
		</request>";

	auto http = HTTP();
	http.clearRequestHeaders();
	http.addRequestHeader("Content-Type", "application/xml");
	//Accept-Charset: utf-8
	http.addRequestHeader("Accept-Charset", "utf-8");
	
	//ISO-8859-1
	//http://www.artlebedev.ru/tools/decoder/
	//ISO-8859-1 → UTF-8
	auto content = post(url, "data", http);
	// content in ISO-8859-1 to UTF-8 encoding but I lose
         //the Cyrillic "<?xml version='1.0' 
encoding='UTF-8'?>отсутствует или неверно задан параметр"
	// I get it "<?xml version='1.0' 
encoding='UTF-8'?>отсутствует или неверно 
задан параметр"
	// How do I change the encoding to UTF-8 in response


	string s = cast(immutable char[])content;
	auto f = File("output.txt","w");  // output.txt file in UTF-8;
	f.write(s);
	f.close;
}


More information about the Digitalmars-d-learn mailing list