从我的网站填写其他网站上的表格

时间:2016-07-16 16:38:10

标签: php

以下地址属于以下形式:       https://webservices.ignou.ac.in/GradecardM/

此表单是asp.net驱动的,其方法设置为post。

我需要使用我在php中编程的网站填写并提交此表单。为了执行操作,我创建了一个表单,但它不起作用。当我填写并提交表单时,只需打开上面提到的链接,而不是返回表单的结果。

我的表格代码如下:

<!DOCTYPE html>
<html>
<head>
<title>Grade Card :: BCA</title>
</head>
<body>
<form method="post" action="https://webservices.ignou.ac.in/GradecardM/Result.asp">
<select name='Program'>
<option value=''>---Select Program---</option>
<option value='BCA'>BCA</option>
<option value='MCA'>MCA</option>
<option value='MP'>MP</option>
<option value='MPB'>MPB</option>
</select>
Enter Enrolment Number: <input type=text name=eno maxlength=9 size=9>
<input type="submit"      value="submit" name="submit">
</body>
</html>

如何解决问题?

2 个答案:

答案 0 :(得分:0)

在这种情况下,您必须使用cURL来执行此操作

什么是cURL in PHP

<?php
    function _curl($url,$post="",$usecookie = false,$_sock = false,$timeout = false) {  
        $ch = curl_init();
        if($post) {
            curl_setopt($ch, CURLOPT_POST ,1);
            curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
        }
        if($timeout){
            curl_setopt($ch, CURLOPT_TIMEOUT,$timeout);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        }
        if($_sock){
                curl_setopt($ch, CURLOPT_PROXY, $_sock);
                curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
        }
        curl_setopt($ch, CURLOPT_URL, $url); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"); 
        if ($usecookie) { 
            curl_setopt($ch, CURLOPT_COOKIEJAR, $usecookie); 
            curl_setopt($ch, CURLOPT_COOKIEFILE, $usecookie);    
        }
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
        $result=curl_exec ($ch); 
        curl_close ($ch); 
        return $result; 
    }
    $url="https://webservices.ignou.ac.in/GradecardM/Result.asp";
    $post = "Program=BCA&eno=2422&submit=Submit&hidden_submit=OK";
    $result = _curl($url,$post,'','','');
    echo $result;
?>

结果

enter image description here

答案 1 :(得分:0)

或者您可以使用此代码

<!DOCTYPE html>
<html>
<head>
<title>Grade Card :: BCA</title>
</head>
<body>
<form method="post" action="https://webservices.ignou.ac.in/GradecardM/Result.asp">
<select name='Program'>
<option value=''>---Select Program---</option>
<option value='BCA'>BCA</option>
<option value='MCA'>MCA</option>
<option value='MP'>MP</option>
<option value='MPB'>MPB</option>
</select>
Enter Enrolment Number: <input type=text name=eno maxlength=9 size=9>
<input type=hidden value='OK' name=hidden_submit>
<input type="submit"      value="submit" name="submit">
</body>
</html>

您缺少隐藏字段xD