HTTP Post Body Parameters

Vahid sabeti.ltd at gmail.com
Tue Aug 1 23:57:29 UTC 2023


Hi,

I want to submit a request to server with "x-www-form-urlencoded" 
header. This is the simplified version of my code:


     auto http = HTTP("https://myurl.com/api");
     http.addRequestHeader("Content-Type", 
"application/x-www-form-urlencoded");
     http.addRequestHeader("Authorization", "SID:TOKEN");

     auto params = "Param1=one&Param2=two";
     http.setPostData(params, "application/x-www-form-urlencoded");

     http.onReceive = (ubyte[] response)
     {
         return cast(string) response;
     };
     http.perform();

This doesn't work as the server not receiving the parameters as 
post body. How can I send parameters as post body (or form data)?

This is the RAW CURL version that I want to write using D:

     curl -X POST "https://myurl.com/api" \
     --data-urlencode "Param1=one" \
     --data-urlencode "Param2=two" \
     -u SID:TOKEN


More information about the Digitalmars-d-learn mailing list