www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Specifying content-type for a POST request using std.net.curl

reply Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
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
Aug 09 2016
next sibling parent reply ketmar <ketmar ketmar.no-ip.org> writes:
http://dpldocs.info/experimental-docs/std.net.curl.HTTP.setPostData.html

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

reading documentation rox!
Aug 09 2016
parent Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
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!
Aug 09 2016
prev sibling parent reply Seb <seb wilzba.ch> writes:
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 ;-)
Aug 09 2016
parent Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
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 ...
Aug 09 2016