使用 libcURL 连续提交 (C/C++)
我是 libcURL 的新手,在执行任务时遇到问题。
我需要连续两次提交来更改文本框。
第一:网络有一个选择框(组)和一个提交按钮。
第二:第一次提交后,您会获得一个特定页面,其中包含
我的代码,但不起作用(两者都提交):
#include <stdio.h>
#include <iostream>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
int main(void)
{
CURL *curl;
CURLcode res;
struct curl_httppost *formpost = NULL;
struct curl_httppost *lastptr = NULL;
struct curl_slist *headerlist = NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "group", CURLFORM_COPYCONTENTS, "ImageSource", CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "Select group", CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "root_ImageSource_I0_Name", CURLFORM_COPYCONTENTS, "weboCam", CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "Save", CURLFORM_END);
curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, buf);
if(curl)
{
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.0.90/admin/config.shtml");
curl_easy_setopt(curl, CURLOPT_USERPWD, "xxxx:xxxx");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
long http_code = 0;
curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code == 200 && res != CURLE_ABORTED_BY_CALLBACK)
{
cout << "Todo ha ido perfecto." << endl; //Succeeded
}
else
{
cout << "Ha habido un error." << endl; //Failed
}
curl_formfree( formpost );
curl_easy_cleanup(curl);
}
另一个问题:代码编译并显示一切正常,但实际上只显示默认页面代码 http ://192.168.0.90/admin/config.shtml
提前致谢
I'm new using libcURL and have a problem to do a task.
I need to do a two submits consecutives to change a textbox.
First: The web have a select box (group) and a submit button.
Second: After de first submit you obtain an specific page with
That my code, but doesn't work(both submits):
#include <stdio.h>
#include <iostream>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
int main(void)
{
CURL *curl;
CURLcode res;
struct curl_httppost *formpost = NULL;
struct curl_httppost *lastptr = NULL;
struct curl_slist *headerlist = NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "group", CURLFORM_COPYCONTENTS, "ImageSource", CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "Select group", CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "root_ImageSource_I0_Name", CURLFORM_COPYCONTENTS, "weboCam", CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "Save", CURLFORM_END);
curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, buf);
if(curl)
{
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.0.90/admin/config.shtml");
curl_easy_setopt(curl, CURLOPT_USERPWD, "xxxx:xxxx");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
long http_code = 0;
curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code == 200 && res != CURLE_ABORTED_BY_CALLBACK)
{
cout << "Todo ha ido perfecto." << endl; //Succeeded
}
else
{
cout << "Ha habido un error." << endl; //Failed
}
curl_formfree( formpost );
curl_easy_cleanup(curl);
}
Another problem: The code compiles and shows that everything goes right but really only show the default page code http://192.168.0.90/admin/config.shtml
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一步完成了。
这段代码完成了第一步。
选择第一个选择。
执行此操作后,我想修改此文本框
总结:我想更改页面第二级中的文本框。问题出在第二个
easy_perform
返回顶层的 libcurl 上。First step done.
This code do the first step.
Take selection of the first select.
After doing this I want to modify this textbox
Summarize: I want to change a textbox in the second level of a page. The problem is libcurl on the second
easy_perform
return to the top level.