如何使用C#以语法形式发布到此表单?

时间:2017-01-12 05:07:59

标签: c# ajax forms web

我正在尝试检查我的礼品卡余额,(我有很多)在以下网站上,我想通过C#程序实现自动化。

https://www.fivebackgift.com/

我感兴趣的源代码中的form1。这是我的代码:

class Program
{


    public static string HttpPost(string url, params object[] postData)
    {
        StringBuilder post = new StringBuilder();
        for (int i = 0; i < postData.Length; i += 2)
            post.Append(string.Format("{0}{1}={2}", i == 0 ? "" : "&", postData[i], postData[i + 1]));
        return HttpPost(url, post.ToString());
    }
    public static string HttpPost(string url, string postData)
    {
        postData = postData.Replace("\r\n", "");
        try
        {
            WebRequest req = WebRequest.Create(url);
            byte[] send = Encoding.Default.GetBytes(postData);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = send.Length;

            Stream sout = req.GetRequestStream();
            sout.Write(send, 0, send.Length);
            sout.Flush();
            sout.Close();

            WebResponse res = req.GetResponse();
            StreamReader sr = new StreamReader(res.GetResponseStream());
            string returnvalue = sr.ReadToEnd();
            return returnvalue;
        }
        catch (Exception ex)
        {
            Debug.WriteLine("POST Error on {0}\n  {1}", url, ex.Message);
            return "";
        }


    }

    static void Main(string[] args)
    {


        HttpPost("https://www.fivebackgift.com/Card/_Login?returnUrl=Transactions", 
            "CardNumber", "CREDIT NUMBER",
            "ExpirationMonth", "MONTH",
            "ExpirationYear", "YEAR",
            "SecurityCode", "CODE");
    }
}

我只是想看看网站是否会给我回复。我得到以下错误:

POST Error on https://www.fivebackgift.com/Card/_Login?returnUrl=Transactions
  The remote server returned an error: (404) Not Found.

如何确定真实网址应该是什么?

0 个答案:

没有答案