Autofill a form of another website and send it

牧云@^-^@ 提交于 2019-11-28 05:55:34

问题


I searched the web and found nothing.

On the website, there is a Input box for a E-Mail address. I would like to fill this field with an e-mail address and the send the form. Then i will get the whole source code from the website.

I don't wanna give this to the URL like "?myvar=test&myvar2=test2". I searched for examples for CURL, but found nothing.

I only want fill the form, send it, and get the source code. Or is there an addon for firefox or a free program?

With best regards KalTo


回答1:


You will need to look at the form action attribute. This should point you to the script the form is posted to. When you have that information you can send a POST request to that url using curl or when in php,

$postdata = http_build_query(
    array(
        'email' => 'youremailaddress'
    )
); 
$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);



回答2:


You can do this, but not the way you expect. To POST a form, you need to first fetch the source code for it (with Curl, or whatever your preference). For each input on the form, you store the name and give it a value. Then you need to send those values with their respective names to the action url of the form, using the method and enctype specified on the form.



来源:https://stackoverflow.com/questions/6787872/autofill-a-form-of-another-website-and-send-it

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