在 libcurl 中发送表单
我需要使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 curl_formadd 向 POST 数据添加更多字段。
如果您想向该示例添加代码,您可以在正在设置表单的部分中添加代码,就在注释上方:
/* 也填写提交字段,即使很少需要 */
。您要添加的代码将如下所示:
提交相同数据的 HTML 表单(假设用户输入了正确的密码)将如下所示:
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:
The HTML form to submit the same data (Assuming the user typed in the correct passwords) would look something like this:
例如,查看“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.