1

HTTP クライアント プログラムを作成しました。その中で、別のプロセスからデータを取得し、それをリクエストの POST フィールドに追加します。しかし、libcurl はコンテンツ タイプを として使用しますapplication/x-www-form-urlencoded。しかし、コンテンツタイプを に変更したいのですが、コンテンツの長さ、エージェントなどの他のフィールドを手動で変更する必要なく、それbinaryだけを変更するにはどうすればよいですか?content-type

              curl_global_init(CURL_GLOBAL_ALL);
              curl =  curl_easy_init(); 
              curl_easy_setopt(curl, CURLOPT_URL, shell_machine);  //shell_machine is xxx.xx.xx.xx:8080/xxx
              curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf);    // buf is my post data
              curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, post_size);  // size of my                             post data

              curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");

              res = curl_easy_perform(curl);
4

1 に答える 1

2

CURLOPT_HTTPHEADERはあなたの友達です。使用法は、httpcustomheader.cの例に示されています。

于 2013-03-31T21:38:22.403 に答える