用libcurl填写帖子表格并获取最终网址
Fill post form with libcurl and get the final url
我需要使用C 和libcurl在网站上授权站点具有复杂的URL,并使用HTTPS网站返回表格
Login field:
<input type="text" maxlength="64" name="edit[id]" id="edit-id" size="60" value="" class="form-text required">
Password field:
<input type="password" name="edit[pass]" id="edit-pass" value="" maxlength="20" size="30" class="form-text required">
Submit button:
<input type="submit" name="op" value="Log in" id="account_login_submit" class="form-submit submit_button button" data-role="none">
当您输入正确的登录 - password对时,站点将您重定向到另一个页面,然后使用&amp; token = ... in get parameters中的代码
我当前的代码:
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "https://url/dialog/oauth?");
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_VERBOSE, true);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "edit[id]=login&edit[pass]=password");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
res = curl_easy_perform(curl);
char url[256];
curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &url);
printf("final [%s]n");
}
现在,它在curlinfo_redirect_url中没有返回,而html的html表单代码
首先,您使用的是curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL..)
错误,因为您应该将指针传递给char *
,但是您的代码将指针传递给Char Buffer的指针。我现在在curlinfo_redirect_url man页面上添加了一个示例,以显示更好。
但最终您可能不应该使用此选项,因为它旨在显示url 它将重定向到,如果您不要求Libcurl重定向 - 您要求Libcurl关注重定向(使用curlopt_followlocation(。
如果您想找出url libcurl重定向到,请改用curlinfo_effective_url。该页面还具有一个示例(现在(以显示如何使用。
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 如何在openssl-ecc中获取十六进制格式的私钥
- 使用Unreal C++获取VR耳机的世界位置/方向
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 从C字符串中获取奇怪的字符串长度
- 为什么我的for循环不能正确获取argv
- 从python中调用C++函数并获取返回值
- 如何获取一个数字的前3位
- 获取字符串的长度并将其分配给数组
- 无法获取菜单选择以运行函数.C++
- 数组长度,为什么从命令行获取时不能使用它?
- Boost Spirit,获取迭代器内部语义动作
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 具有默认值的引用获取函数
- 用libcurl填写帖子表格并获取最终网址
- 如何获取表格的大小