Thread overview | |||||
---|---|---|---|---|---|
|
September 03, 2020 How to use std.net.curl with specific curl query? | ||||
---|---|---|---|---|
| ||||
I have a specific curl query that I want to use in a D script via std.net.curl. Here is the query: curl -v -X POST --data-urlencode "username=user@gmail.net" --data-urlencode "password=12345" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -u "client_name:CLIENT_PASS" "https://some.i.net/oauth/token?grant_type=password" The std.net.curl post documentation says that it needs a URL and a key:value map as arguments. However, what should be the key and what should be the value given the above query? There are two "--data-urlencode" parameters so the map cannot have two identical keys. Unfortunately the documentation is lacking both information and examples. Can somebody help me out here please? In addition, the current "post" ddoc example fails to run throwing "std.net.curl.CurlException@std/net/curl.d(4402): Couldn't resolve host name on handle 55DF372ABBC0" |
September 03, 2020 Re: How to use std.net.curl with specific curl query? | ||||
---|---|---|---|---|
| ||||
Posted in reply to tastyminerals | On Thursday, 3 September 2020 at 11:14:14 UTC, tastyminerals wrote: > I have a specific curl query that I want to use in a D script via std.net.curl. > > Here is the query: > > curl -v -X POST > --data-urlencode "username=user@gmail.net" > --data-urlencode "password=12345" > -H "Content-Type: application/x-www-form-urlencoded" > -H "Accept: application/json" > -u "client_name:CLIENT_PASS" > "https://some.i.net/oauth/token?grant_type=password" > > The std.net.curl post documentation says that it needs a URL and a key:value map as arguments. However, what should be the key and what should be the value given the above query? There are two "--data-urlencode" parameters so the map cannot have two identical keys. Unfortunately the documentation is lacking both information and examples. Can somebody help me out here please? > > In addition, the current "post" ddoc example fails to run throwing "std.net.curl.CurlException@std/net/curl.d(4402): Couldn't resolve host name on handle 55DF372ABBC0" Figured it out, just needed to read further docs. auto http = HTTP("https://some.i.net/oauth/token?grant_type=password"); auto data = "username=user@gmail.net&password=12345"; http.setPostData(data, "application/x-www-form-urlencoded"); http.addRequestHeader("Content-Type", "application/x-www-form-urlencoded"); http.addRequestHeader("Accept", "application/json"); http.setAuthentication("client_name", "CLIENT_PASS"); http.perform |
September 04, 2020 Re: How to use std.net.curl with specific curl query? | ||||
---|---|---|---|---|
| ||||
Posted in reply to tastyminerals | Nice, I have been having this problem for quite a while too. Thanks |
Copyright © 1999-2021 by the D Language Foundation