machinezone / IXWebSocket

websocket and http client and server library, with TLS support and very few dependencies
BSD 3-Clause "New" or "Revised" License
539 stars 173 forks source link

How to do httpclient post right ?! #440

Closed Hedgezzz closed 1 year ago

Hedgezzz commented 1 year ago

I have the following code ::

string req="https://testnet.binancefuture.com/fapi/v1/order?symbol=BTCUSDT&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=21002.2&recvWindow=60000&timestamp=1676439415772&signature=28ba85cfdb2b44cf12d89281c6ef7704a4211224b6b92c81763ec394b2e8db87" ;

HttpClient httpClient;
HttpRequestArgsPtr args = httpClient.createRequest();
WebSocketHttpHeaders headers;
headers["X-MBX-APIKEY"] = "XXXXXXXXXXXXXXXXXXXXX";
args->extraHeaders = headers;

    HttpResponsePtr response;
    std::string ixurl = "https://testnet.binancefuture.com"; 
    response = httpClient.request(ixurl, "POST",req, args,0);
    auto body = response->body;
    cout << body << endl ;

this source would core dump , what should I do to make this work ?!

BTW , the following works in curl ::

curl -H "X-MBX-APIKEY: XXXXXXXXXXXXXXXXXXXXX" -X POST "https://testnet.binancefuture.com/fapi/v1/order?symbol=BTCUSDT&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=21002.2&recvWindow=60000&timestamp=1676439415772&signature=28ba85cfdb2b44cf12d89281c6ef7704a4211224b6b92c81763ec394b2e8db87"

bsergean commented 1 year ago

can you catch the crash in a debugger ?

Hedgezzz commented 1 year ago

look like I use the following post function can work perfectly :

sprintf(queryString,"%s","symbol=ETHUSDT&side=SELL&type=LIMIT&timeInForce=GTC&quantity=0.123&price=26006.2&recvWindow=60000");

args->body = queryString ;
auto response = httpClient.post(url,args->body, args);
bsergean commented 1 year ago

Cool, looks like you found the solution to your problem. I will close this issue then.