Thread overview
Specifying content-type for a POST request using std.net.curl
Aug 09, 2016
ketmar
Aug 09, 2016
Seb
August 09, 2016
Hello all,

I'm currently writing a little client app whose job is to make a POST request to a vibe.d webserver and output the response.  However, vibe.d is picky about the content-type of the request body, and so far as I can see there is no way to specify this via the `std.net.curl.post` API.

So far as I can see from the vibe.d log output, `post` is using the `text/plain` content type, to which vibe.d objects (rightly) because the content is not UTF8.  It's a little bizarre that `text/plain` is chosen, because the input data is `void[]` or `ubyte[]` data.

Can anyone advise (if it's possible at all) how to specify the content type for the post request body using std.net.curl (or an alternative)?

Thanks & best wishes,

    -- Joe
August 09, 2016
http://dpldocs.info/experimental-docs/std.net.curl.HTTP.setPostData.html

https://dlang.org/phobos/std_net_curl.html#.HTTP.setPostData

reading documentation rox!
August 09, 2016
On Tuesday, 9 August 2016 at 14:07:48 UTC, Joseph Rushton Wakeling wrote:
> Hello all,
>
> I'm currently writing a little client app whose job is to make a POST request to a vibe.d webserver and output the response.  However, vibe.d is picky about the content-type of the request body, and so far as I can see there is no way to specify this via the `std.net.curl.post` API.
>
> So far as I can see from the vibe.d log output, `post` is using the `text/plain` content type, to which vibe.d objects (rightly) because the content is not UTF8.  It's a little bizarre that `text/plain` is chosen, because the input data is `void[]` or `ubyte[]` data.
>
> Can anyone advise (if it's possible at all) how to specify the content type for the post request body using std.net.curl (or an alternative)?
>
> Thanks & best wishes,
>
>     -- Joe

There is also

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

Which I find in general more intuitive to use ;-)

August 09, 2016
On Tuesday, 9 August 2016 at 14:21:09 UTC, ketmar wrote:
> http://dpldocs.info/experimental-docs/std.net.curl.HTTP.setPostData.html
>
> https://dlang.org/phobos/std_net_curl.html#.HTTP.setPostData
>
> reading documentation rox!

Yea, mea culpa.  I had actually glanced at that but was asking on the assumption that I might have misunderstood something about the simpler functions -- it was a bit odd that (for example) a `post` call whose input data was `void[]` or `ubyte[]` would still be treated as text content-type.

In any case, I now have a working solution using HTTP.setPostData, so all's well ;-)  Thanks!
August 09, 2016
On Tuesday, 9 August 2016 at 14:30:21 UTC, Seb wrote:
> There is also
>
> https://github.com/ikod/dlang-requests
>
> Which I find in general more intuitive to use ;-)

Interesting, I'd not come across that before.  Thanks -- I'll give it a glance some time ...