如何为php链接生成URL

时间:2014-08-11 08:59:20

标签: c#

这是短信发件人网站,我想为此制作一个C#功能。在第一,我想生成链接。例如,我尝试了http://www.magtifun.ge/index.php?page=11&lang=en&act=1&user=mamasha&password=7504a,但它不起作用。

这里是该网站的Inspect Element

的代码
<!--

 Start user Action Form 

-->
<form action="index.php?page=11&lang=en" method="post" name="user_action">
    <!--

     Form Header 

    -->
    <div class="tbl_header">

        Log In

    </div>
    <!--

     Action 

    -->
    <input id="act" type="hidden" value="1" name="act"></input>
    <!--

     User 

    -->
    <p class="space_top"></p>
    <p>
        <input id="user" class="round_border medium_box" type="text" name="user"></input>
    </p>
    <!--

     Password 

    -->
    <p></p>
    <p>
        <input id="password" class="round_border medium_box" type="password" name="password"></input>
    </p>
  

我想这样做,但它不起作用。这是对的吗?

  {
     string URL = "http://www.magtifun.ge/index.php?page=11&lang=ge";
                WebClient webClient = new 

WebClient();
        NameValueCollection formData = new NameValueCollection();
        formData["act"] = "1";
        formData["user"] = "mamasha";
        formData["password"] = "75045a";

        byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
        string responsefromserver = Encoding.UTF8.GetString(responseBytes);
        Console.WriteLine(responsefromserver);
        webClient.Dispose();

        Thread.Sleep(5);
        send("591931123", "Hello vaxo");

        Console.ReadKey();
    }
    public static void send(string n, string t){
        ASCIIEncoding encoding = new ASCIIEncoding();
        string postDate = "recipient=" + n;
        postDate +="&message_body=" + t;
        byte[] date = encoding.GetBytes(postDate);
        WebRequest req = WebRequest.Create("http://www.magtifun.ge/scripts/sms_send.php");
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        req.ContentLength = date.Length;

        Stream stream = req.GetRequestStream();
        stream.Write(date, 0, date.Length);
        stream.Close();

        WebResponse respons = req.GetResponse();
        stream = respons.GetResponseStream();

        StreamReader st = new StreamReader(stream);
        Console.WriteLine(st.ReadToEnd());
        st.Close();
        stream.Close();
    }
}

}

1 个答案:

答案 0 :(得分:0)

您必须对http://www.magtifun.ge/index.php页面执行POST请求。我认为没有cookie它将无法工作,因为该网站需要授权。