在 libcurl 中发送表单

发布于 2024-08-29 20:44:08 字数 181 浏览 8 评论 0原文

我需要使用 libcurl 将文件发送到网络服务器。我在curl网站上看到了一个例子,并正在尝试实现它。这是 postit2.c 示例。有人可以告诉我如何扩展它以能够发送用户名和密码

i need to send a file to a webserver using libcurl. i saw one of the examples in the curl website and am trying to implement it. it is the postit2.c example. can someone tell me how i might extend this to be able to send username and password as well

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

避讳 2024-09-05 20:44:08

使用 curl_formadd 向 POST 数据添加更多字段。

如果您想向该示例添加代码,您可以在正在设置表单的部分中添加代码,就在注释上方: /* 也填写提交字段,即使很少需要 */

您要添加的代码将如下所示:

curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "user", //the name of the data to send
             CURLFORM_COPYCONTENTS, "username", //the users username
             CURLFORM_END);

curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "pass", //the name of the data to send
             CURLFORM_COPYCONTENTS, "mypass", //the users password
             CURLFORM_END);

提交相同数据的 HTML 表单(假设用户输入了正确的密码)将如下所示:

Username: <input type="text" name="user" /> <br />
Password: <input type="password" name="pass" />

Use curl_formadd to add some more fields to the POST data.

If you wanted to add code to that sample you would do in the section where the form is being setup, just above the comment: /* Fill in the submit field too, even if this is rarely needed */.

The code you would add would be something like this:

curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "user", //the name of the data to send
             CURLFORM_COPYCONTENTS, "username", //the users username
             CURLFORM_END);

curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "pass", //the name of the data to send
             CURLFORM_COPYCONTENTS, "mypass", //the users password
             CURLFORM_END);

The HTML form to submit the same data (Assuming the user typed in the correct passwords) would look something like this:

Username: <input type="text" name="user" /> <br />
Password: <input type="password" name="pass" />
七月上 2024-09-05 20:44:08

例如,查看“res = curl_easy_perform(curl);” postit2.c 中的部分...您可以添加 'printf("CurlCode: %d", res);'。如果result为0,则表示提交成功。

For example, look 'res = curl_easy_perform(curl);' part in postit2.c...You can add 'printf("CurlCode: %d", res);'. If result is 0, it means that the submission is successfull.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文