How do I automatically complete a php form using C++?

旧街凉风 提交于 2019-12-11 10:40:15

问题


What is a simple way to complete a php form, submit it and get the resulting data ? It doesn't have to be C++ but I know it best, I have the last visual studio and I need a windows executable.

I found something that does this in ruby, it's called mechanize, I'm wondering if there's something similar for C++ ?


回答1:


If it's a general form (i.e. you want it to work well with any HTML form, then probably your best bet is to utilize an HTML parsing library, such as http://www.codeproject.com/KB/library/GomzyHTMLReader.aspx. What you'll probably want to do is have the parsing algorithm parse the HTML document, find all of the inputs that are expected, then craft an HTTP request with the responses (see How do you make a HTTP request with C++?).

There are probably a few things that you'll need from the HTML form:

  1. The action to take after form submission (from the tag's action attribute).
  2. The method (GET or POST). If it's GET, then your work will probably be simple, as you'll be able to simply add it to the URI as parameters. If it's POST, it'll be a little more difficult, but not incredibly so.
  3. Whether or not the connection is SSL encrypted.

I'll be honest with you, some forms are going to be very difficult to automatically enter. Many web sites specifically discourage this type of behavior, so unless it's something you've specifically crafted, or that is designed to be filled out automatically, it could be pretty tough.



来源:https://stackoverflow.com/questions/4810845/how-do-i-automatically-complete-a-php-form-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!