Libcurl 模拟登录wordpress发布文章POST问题,在线等

su22289 2016-09-24 03:01:45
通过获取返回的网页,表单是填写成功,但是没有成功发布,因为wordpress发布的时候,会每次生产一个动态码我已经获取到了,并加入到提交数据中,请大神帮我看看,发布失败的原因



//发布文章
void CCURL模拟POST登录Dlg::OnBnClickedButton3()
{
CURL *curl;
CURLcode res;
char * sUrl = "http://blog.ledshoestore.com/wp-admin/post-new.php";//跳转的地址
char * sUrl2 = "http://blog.ledshoestore.com/wp-admin/post-new.php?wp-post-new-reload=true"; //提交的服务器地址
struct curl_slist *headerlist = NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, buf);
//接收处理动态码,另一个控件获取,保存在全局变量中
char urlpost[3000] = "";
string nimeixxoo2 = "_wpnonce=" + nimeiStr4 + "&_wp_http_referer=%2Fwp-admin%2Fpost-new.php&user_ID=2&action=editpost&originalaction=editpost&post_author=2&post_type=post&original_post_status=auto-draft&referredby=http%3A%2F%2Fblog.ledshoestore.com%2Fwp-admin%2Fpost.php%3Fpost%3D168%26action%3Dedit&_wp_original_http_referer=http%3A%2F%2Fblog.ledshoestore.com%2Fwp-admin%2Fpost.php%3Fpost%3D168%26action%3Dedit&auto_draft=&post_ID=" + nimeipage + "&meta-box-order-nonce=fdead1fe6d&closedpostboxesnonce=acae0608c2&post_title=123&samplepermalinknonce=6df815118f&content=123&wp-preview=&hidden_post_status=draft&post_status=draft&hidden_post_password=&hidden_post_visibility=public&visibility=public&post_password=&mm=09&jj=23&aa=2016&hh=19&mn=56&ss=29&hidden_mm=09&cur_mm=09&hidden_jj=23&cur_jj=23&hidden_aa=2016&cur_aa=2016&hidden_hh=19&cur_hh=19&hidden_mn=56&cur_mn=56&original_publish=Publish&publish=Publish&post_format=0&post_category%5B%5D=0&post_category%5B%5D=6&post_category%5B%5D=3&tax_input%5Bpost_tag%5D=aaaaa%2Cbbbbb&newtag%5Bpost_tag%5D=&excerpt=&trackback_url=&metakeyinput=&metavalue=&_ajax_nonce-add-meta=9b3c1eca02&advanced_view=1&comment_status=open&ping_status=open&post_name=";
const char * nimeixxoo =nimeixxoo2.c_str();
sprintf(urlpost, nimeixxoo);
if (curl)
{
curl_easy_setopt(curl, CURLOPT_POST,true);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, urlpost);//POST提交数据。
curl_easy_setopt(curl, CURLOPT_URL, sUrl);//提交的服务器地址
curl_easy_setopt(curl, CURLOPT_REFERER, sUrl2);//这个没有,结果都一样
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie_login.txt");//提交登录的cookie
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie_postpage2.txt");//保存发布后的cookie
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data2);
char * fileUrlNimei = "C:\\Users\\admin\\Desktop\\nimei3.txt";
FILE * nimeiFile;
nimeiFile = fopen(fileUrlNimei, "a+");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, nimeiFile);
#ifdef SKIP_PEER_VERIFICATION
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
#endif
#ifdef SKIP_HOSTNAME_VERFICATION
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
/* free slist */
curl_slist_free_all(headerlist);
//curl_formfree(formpost);
curl_global_cleanup();
}
}


返回网页

...全文
341 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
su22289 2016-09-29
  • 打赏
  • 举报
回复
已经搞定,是提交的地址错了
赵4老师 2016-09-27
  • 打赏
  • 举报
回复
建议楼主先学会使用抓包软件比如wireshark
su22289 2016-09-26
  • 打赏
  • 举报
回复

但是发布后的结果,这两个都没有成功

su22289 2016-09-26
  • 打赏
  • 举报
回复
这是抓包数据,有文章类目和标签

su22289 2016-09-26
  • 打赏
  • 举报
回复
提交地址错了,现在注册和发布,都成功了,但是文章类目和标签,没有成功,这是什么回事 提交的数据,都有,但是没有成功
encoderlee 2016-09-25
  • 打赏
  • 举报
回复
用Fiddler2抓包看看,浏览器发的POST和你的程序发的POST有何差异之处
oyljerry 2016-09-24
  • 打赏
  • 举报
回复
应该是还有参数没有构造正确。可以看浏览器提交的数据

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧