通过基于桌面的应用程序的URL发送信息

时间:2010-01-13 05:47:46

标签: c#

我必须将一些信息传递给weburl并从中获得回复。

这必须在按c#。

制作的基于桌面的应用程序的按钮上完成

4 个答案:

答案 0 :(得分:3)

WebClient。DownloadStringUploadString

答案 1 :(得分:3)

StringBuilder sb  = new StringBuilder();

// used on each read operation
byte[]        buf = new byte[8192];

// prepare the web page we will be asking for
HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create("http://www.feefifofum.com/login.aspx?userid=XXX&pass=YYYY");

// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// we will read data via the response stream
Stream resStream = response.GetResponseStream();

string tempString = null;
int    count      = 0;
do
{
    // fill the buffer with data
    count = resStream.Read(buf, 0, buf.Length);

    // make sure we read some data
    if (count != 0)
    {
        // translate from bytes to ASCII text
        tempString = Encoding.ASCII.GetString(buf, 0, count);

        // continue building the string
        sb.Append(tempString);
    }
}
while (count > 0); // any more data to read?

// print out page source
Console.WriteLine(sb.ToString());

答案 2 :(得分:1)

使用WebClient.DownloadString并将您的值作为QueryString传递。像下面的东西

string s;
using (WebClient wc = new WebClient())
{
  wc.QueryString.Add ("Param1", "param1value");  
  wc.QueryString.Add ("Param2", "param2value");           
  s = wc.DownloadString (webaddress);
}

有关方法详情,请访问MSDN

答案 3 :(得分:1)

将信息发送到URL并获取信息也听起来有点像Web服务的工作。您是否考虑过使用网络服务? (假设您拥有对URL的控制/访问权限)

相关问题