xml utf-8 encoding error
graw-prog via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 28 21:41:34 PDT 2017
Hi, I'm having some trouble getting an xml file using
std.net.curl. I'm using get() to receive device info from a roku
television using this code:
char[] inputQuery(string input) {
string url = ip ~ "query/" ~ input;
auto client = HTTP();
auto content = get(url,client);
return content;
}
I've had no problem in the past using similar code to receive
JSON data from a web server. However in this case I run into this
error:
std.encoding.EncodingException at std/encoding.d(2346): Unrecognized
Encoding: "utf-8"
----------------
??:? std.encoding.EncodingScheme
std.encoding.EncodingScheme.create(immutable(char)[]) [0x9773ff]
/usr/include/dmd/phobos/std/net/curl.d:1196 char[]
std.net.curl._decodeContent!(char)._decodeContent(ubyte[],
immutable(char)[]) [0x7951cb]
/usr/include/dmd/phobos/std/net/curl.d:1049 char[]
std.net.curl._basicHTTP!(char)._basicHTTP(const(char)[],
const(void)[], std.net.curl.HTTP) [0x793559]
/usr/include/dmd/phobos/std/net/curl.d:540 char[]
std.net.curl.get!(std.net.curl.HTTP, char).get(const(char)[],
std.net.curl.HTTP) [0x795b77]
source/backend.d:26 immutable(char)[]
backend.inputQuery(immutable(char)[]) [0x7886bd]
When I use cURL directly to get the info I get this:
curl -v --request GET http://192.168.1.140:8060/query/device-info
Connected to 192.168.1.140 (192.168.1.140) port 8060 (#0)
> GET /query/device-info HTTP/1.1
> Host: 192.168.1.140:8060
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Roku UPnP/1.0 MiniUPnPd/1.4
< Content-Length: 1826
< Cache-Control: no-cache
< Content-Type: text/xml; charset="utf-8"
<
<?xml version="1.0" encoding="UTF-8" ?>
This seems to be the relevant code in curl.d:
private auto _decodeContent(T)(ubyte[] content, string encoding)
{
static if (is(T == ubyte))
{
return content;
}
else
{
import std.format : format;
// Optimally just return the utf8 encoded content
if (encoding == "UTF-8"||encoding == "utf-8")
return cast(char[])(content);
// The content has to be re-encoded to utf8
auto scheme = EncodingScheme.create(encoding);
enforce!CurlException(scheme !is null,
format("Unknown encoding '%s'",
encoding));
I'm not sure what the problem is. It seems to be may the
lowercase 'utf-8' in the charset section but I'm not sure if the
problem is some mistake I made, a bug in DMD or just lousy xml.
Either way is there any way around this issue?
More information about the Digitalmars-d-learn
mailing list