2017-01-26 1 views
2

EOF Je suis en train de faire des requêtes HTTP POST avec curl_easy_perform(), mais lorsque le code atteintcurl_easy_perform avec POST attend

res = curl_easy_perform(curl); 

il attend EOF. Lorsque je clique sur Ctrl + D, le code se termine avec succès. J'utilise XCode IDE. Je rencontre le même problème même lorsque le programme s'exécute en tant qu'exécutable compilé à partir du terminal.

Ceci est ma fonction POST avec les paramètres papillotes:

int BitfinexAPI:: 
DoPOSTrequest(const string &UrlEndPoint, const string &params, string &result) 
{ 

    if(curl) { 

     string url = APIurl + UrlEndPoint; 
     string payload; 
     string signature; 
     getBase64(params, payload); 
     getHmacSha384(secretKey, payload, signature); 

     // Headers 
     struct curl_slist *httpHeaders = NULL; 
     httpHeaders = curl_slist_append(httpHeaders, ("X-BFX-APIKEY:" + accessKey).c_str()); 
     httpHeaders = curl_slist_append(httpHeaders, ("X-BFX-PAYLOAD:" + payload).c_str()); 
     httpHeaders = curl_slist_append(httpHeaders, ("X-BFX-SIGNATURE:" + signature).c_str()); 
     httpHeaders = curl_slist_append(httpHeaders, ("Expect:")); 

     curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); // debug option 
     curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); 
     curl_easy_setopt(curl, CURLOPT_POST, 1); 
     curl_easy_setopt(curl, CURLOPT_HTTPHEADER, httpHeaders); 
     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); 
     curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result); 
     res = curl_easy_perform(curl); 

     // libcurl internal error handling 
     if (res != CURLE_OK) 
     { 
      cout << "Libcurl error in DoPOSTRequest(), code:\n"; 
      return res; 
     } 
     return res; 

    } 
    else 
    { 
     // curl not properly initialized curl = NULL 
     return curlERR; 

    } 
} 

Et ceci est sortie de CURLOPT_VERBOSE, 0L après avoir frappé Ctrl-D après < HTTP/1.1 100 Continuer ligne:

* Trying 104.16.175.181... 
* TCP_NODELAY set 
* Connected to api.bitfinex.com (104.16.175.181) port 443 (#0) 
* TLS 1.2 connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 
* Server certificate: ssl453718.cloudflaressl.com 
* Server certificate: COMODO ECC Domain Validation Secure Server CA 2 
* Server certificate: COMODO ECC Certification Authority 
> POST /v1/account_infos/ HTTP/1.1 
Host: api.bitfinex.com 
Accept: */* 
X-BFX-APIKEY:NKc8RCJUDPfp1R8enTPSAi0soozYFn9MezjzmnFQJ3X 
X-BFX-PAYLOAD:eyJyZXF1ZXN0IjoiL3YxL2FjY291bnRfaW5mb3MiLCJub25jZSI6IjE0ODU0NjIyNDUzNzE2MTYifQ== 
X-BFX-SIGNATURE:95c396c792b59b8084b9f2523b6b7c0e948ae555e2677a07fd42e54050360a44f8f0e184db5b9fa63c4635816180ba1e 
Content-Type: application/x-www-form-urlencoded 
Expect: 100-continue 

< HTTP/1.1 100 Continue 
< HTTP/1.1 200 OK 
< Date: Thu, 26 Jan 2017 20:24:05 GMT 
< Content-Type: application/json; charset=utf-8 
< Transfer-Encoding: chunked 
< Connection: keep-alive 
< Set-Cookie: __cfduid=d3d747333090623a13f70c430103686ed1485462245; expires=Fri, 26-Jan-18 20:24:05 GMT; path=/; domain=.bitfinex.com; HttpOnly 
< Strict-Transport-Security: max-age=31536000 
< X-Frame-Options: SAMEORIGIN 
< X-XSS-Protection: 1; mode=block 
< X-Content-Type-Options: nosniff 
< Vary: Accept-Encoding 
< ETag: W/"0ac5694d4f0d0485ba2e4640ac79cc40" 
< Cache-Control: no-cache 
< X-Request-Id: b5f58f5f-473f-428b-a889-74c2e7b43278 
< X-Runtime: 0.029113 
< Expires: Thu, 26 Jan 2017 20:24:04 GMT 
< X-Frame-Options: SAMEORIGIN 
< Server: cloudflare-nginx 
< CF-RAY: 3276afba2efd3e20-PRG 
< 
* Curl_http_done: called premature == 0 
* Connection #0 to host api.bitfinex.com left intact 
[{"maker_fees":"0.1","taker_fees":"0.2","fees":[{"pairs":"BTC","maker_fees":"0.1","taker_fees":"0.2"},{"pairs":"LTC","maker_fees":"0.1","taker_fees":"0.2"},{"pairs":"ETH","maker_fees":"0.1","taker_fees":"0.2"},{"pairs":"ETC","maker_fees":"0.1","taker_fees":"0.2"},{"pairs":"ZEC","maker_fees":"0.1","taker_fees":"0.2"},{"pairs":"XMR","maker_fees":"0.1","taker_fees":"0.2"}]}] 
0 
Program ended with exit code: 0 

Répondre

1

Problème: Le code définit CURLOPT_POST mais il ne semble pas indiquer de méthode pour libc url pour envoyer des données dans cette demande POST? Cela fera libcurl utiliser la fonction de lecture interne par défaut, qui STDIN ...

Fix: Fournir les données POST avec CURLOPT_POSTFIELDS ou mettre en place la fonction de rappel de lecture avec CURLOPT_READFUNCTION si vous préférez.

+0

Vous avez 100% raison. 'curl_easy_setopt (curl, CURLOPT_POSTFIELDS," \ n ");' a résolu le problème.Merci. –