Thread overview
HTTP-methods and encoding
Apr 07, 2018
Vindex
Apr 07, 2018
Seb
Apr 07, 2018
Vindex
Apr 08, 2018
ikod
Apr 08, 2018
Vindex
April 07, 2018
There is an error on some sites when using HTTP-methods (std.net.curl.get, std.net.curl.post):
std.encoding.EncodingException@std/encoding.d(2505): Unrecognized Encoding: utf8

Is there a beautiful way around it?
For the GET-method I use the download() and readText(). But for the POST-method I can not come up with an alternative solution.
April 07, 2018
On Saturday, 7 April 2018 at 13:02:39 UTC, Vindex wrote:
> There is an error on some sites when using HTTP-methods (std.net.curl.get, std.net.curl.post):
> std.encoding.EncodingException@std/encoding.d(2505): Unrecognized Encoding: utf8
>
> Is there a beautiful way around it?
> For the GET-method I use the download() and readText(). But for the POST-method I can not come up with an alternative solution.

That's weird. std.net.curl should be able to handle UTF-8.
What content are you trying to download/post?
Maybe you can open a bug report for it?

In any case, you might want to checkout requests:

https://github.com/ikod/dlang-requests

It's by far more convenient to use than std.net.curl

April 07, 2018
On Saturday, 7 April 2018 at 15:58:14 UTC, Seb wrote:
> On Saturday, 7 April 2018 at 13:02:39 UTC, Vindex wrote:
>> There is an error on some sites when using HTTP-methods (std.net.curl.get, std.net.curl.post):
>> std.encoding.EncodingException@std/encoding.d(2505): Unrecognized Encoding: utf8
>>
>> Is there a beautiful way around it?
>> For the GET-method I use the download() and readText(). But for the POST-method I can not come up with an alternative solution.
>
> That's weird. std.net.curl should be able to handle UTF-8.
> What content are you trying to download/post?
> Maybe you can open a bug report for it?
>
> In any case, you might want to checkout requests:
>
> https://github.com/ikod/dlang-requests
>
> It's by far more convenient to use than std.net.curl

The problem is that "utf-8" (or "UTF-8") is required instead of "utf8".

I tried to get HTML and JSON. For example, this GET-query returns error:
"https://yobit.net/api/3/ticker/btc_usd"

Thank you for the advice
April 08, 2018
On Saturday, 7 April 2018 at 23:54:21 UTC, Vindex wrote:
> On Saturday, 7 April 2018 at 15:58:14 UTC, Seb wrote:
>> On Saturday, 7 April 2018 at 13:02:39 UTC, Vindex wrote:
>>> There is an error on some sites when using HTTP-methods (std.net.curl.get, std.net.curl.post):
>>> std.encoding.EncodingException@std/encoding.d(2505): Unrecognized Encoding: utf8
>>>
>>> Is there a beautiful way around it?
>>> For the GET-method I use the download() and readText(). But for the POST-method I can not come up with an alternative solution.
>>
>> That's weird. std.net.curl should be able to handle UTF-8.
>> What content are you trying to download/post?
>> Maybe you can open a bug report for it?
>>
>> In any case, you might want to checkout requests:
>>
>> https://github.com/ikod/dlang-requests
>>
>> It's by far more convenient to use than std.net.curl
>
> The problem is that "utf-8" (or "UTF-8") is required instead of "utf8".
>
> I tried to get HTML and JSON. For example, this GET-query returns error:
> "https://yobit.net/api/3/ticker/btc_usd"
>
> Thank you for the advice

Hello,

"utf-8" (or "UTF-8") is required instead of "utf8" - explain, please.

Anyway this code works as expected:

import requests;
import std.stdio;
import std.format;

void main() {
    auto rq = Request();
    auto rs = rq.get("https://yobit.net/api/3/ticker/btc_usd");
    writeln(rs.responseBody);
}

output:

{"btc_usd":{"high":7216.09463851,"low":6950,"avg":7083.04731925,"vol":753989.73116823,"vol_cur":105.94453165,"last":7114,"buy":7114.00000000,"sell":7135.19110000,"updated":1523170067}}

April 08, 2018
On Sunday, 8 April 2018 at 06:51:22 UTC, ikod wrote:
> On Saturday, 7 April 2018 at 23:54:21 UTC, Vindex wrote:
>> On Saturday, 7 April 2018 at 15:58:14 UTC, Seb wrote:
>>> On Saturday, 7 April 2018 at 13:02:39 UTC, Vindex wrote:
>>>> There is an error on some sites when using HTTP-methods (std.net.curl.get, std.net.curl.post):
>>>> std.encoding.EncodingException@std/encoding.d(2505): Unrecognized Encoding: utf8
>>>>
>>>> Is there a beautiful way around it?
>>>> For the GET-method I use the download() and readText(). But for the POST-method I can not come up with an alternative solution.
>>>
>>> That's weird. std.net.curl should be able to handle UTF-8.
>>> What content are you trying to download/post?
>>> Maybe you can open a bug report for it?
>>>
>>> In any case, you might want to checkout requests:
>>>
>>> https://github.com/ikod/dlang-requests
>>>
>>> It's by far more convenient to use than std.net.curl
>>
>> The problem is that "utf-8" (or "UTF-8") is required instead of "utf8".
>>
>> I tried to get HTML and JSON. For example, this GET-query returns error:
>> "https://yobit.net/api/3/ticker/btc_usd"
>>
>> Thank you for the advice
>
> Hello,
>
> "utf-8" (or "UTF-8") is required instead of "utf8" - explain, please.
>
> Anyway this code works as expected:
>
> import requests;
> import std.stdio;
> import std.format;
>
> void main() {
>     auto rq = Request();
>     auto rs = rq.get("https://yobit.net/api/3/ticker/btc_usd");
>     writeln(rs.responseBody);
> }
>
> output:
>
> {"btc_usd":{"high":7216.09463851,"low":6950,"avg":7083.04731925,"vol":753989.73116823,"vol_cur":105.94453165,"last":7114,"buy":7114.00000000,"sell":7135.19110000,"updated":1523170067}}

Thank you, I will use requests.
Function _decodeContent() in curl.d consists:

if (encoding == "UTF-8") return cast(char[])(content);
auto scheme = EncodingScheme.create(encoding);
enforce!CurlException(scheme !is null, format("Unknown encoding '%s'", encoding));

Encoding name (in std.encoding) is transferred to the lower case and matches are checked among the supported encoding names. There is "utf-8", but there is no "utf8" (without the hyphen).