Home > Software design >  How desactivate "Transfer-Encoding" in PUT request header
How desactivate "Transfer-Encoding" in PUT request header

Time:01-07

I create request with curl but, in the header, curl add the option "Transfer-Encoding" but, the API a would like use dont know this option. How i can delete this option ?

CodePudding user response:

I solve my problem with this line : curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");

CodePudding user response:

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);

curl_easy_setopt(curl, CURLOPT_URL, end_point);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");

buff = credential_scope;
buff = ACCESS_KEY   string("/")   buff;
printf("%s\n",buff.c_str());


string test_val = "";
char tampon[8];
for (int i = 0; i < SHA256_HASH_SIZE; i  )
{
    sprintf(tampon,"x",signature[i]);
    test_val  = tampon;
}

struct data config;
config.trace_ascii = 1;

buffUser = (string) "Authorization:"  ALGORITHM  " Credential="  ACCESS_KEY   "/"   credential_scope   ",SignedHeaders="   signed_header   ",Signature="   test_val;
chunk = curl_slist_append(chunk,buffUser.c_str());

buffUser = "x-amz-content-sha256:"   payload_hash;
chunk = curl_slist_append(chunk,buffUser.c_str());

buff = amzdate;
buffUser = "x-amz-date:"   buff;
chunk = curl_slist_append(chunk,buffUser.c_str());


        buffUser = "Content-Length: 1";
        chunk = curl_slist_append(chunk,buffUser.c_str());

        buffUser="Connection: keep-alive";
        chunk = curl_slist_append(chunk,buffUser.c_str());

        buffUser="Expect: 100-continue";
        chunk = curl_slist_append(chunk,buffUser.c_str());

        buffUser="Content-Type: text/plain";
        chunk = curl_slist_append(chunk,buffUser.c_str());

/*buffUser = " Transfer-Encoding:-1";
chunk = curl_slist_append(chunk,buffUser.c_str());*/

curl_easy_setopt (curl,CURLOPT_HTTP_TRANSFER_DECODING,1);

curl_easy_setopt (curl, CURLOPT_DEBUGFUNCTION , my_trace);
curl_easy_setopt (curl, CURLOPT_DEBUGDATA , &config);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
//curl_easy_setopt(curl,CURLOPT_INFILESIZE,1);




curl_easy_setopt(curl,CURLOPT_HTTPHEADER,chunk);



curl_easy_setopt(curl,CURLOPT_READDATA,fileOpen);
curl_easy_setopt(curl,CURLOPT_READFUNCTION,write_data);
curl_easy_setopt(curl,CURLOPT_INFILE,fileOpen);

  res = curl_easy_perform(curl);


  if(res != CURLE_OK)
    fprintf(stderr, "curl_easy_perform() failed: %s\n",
            curl_easy_strerror(res));

  curl_easy_cleanup(curl);
// }
  fclose (fileOpen);
printf("Fin programme \n");
return 0;

My code and with the otpion curl_easy_setopt(curl, CURLOPT_PUT, 1); in default, CURL create the option "Encoding-Content". For fix my bug, i use curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); it don't have option per default and fixe my bug.

  •  Tags:  
  • Related