本文介绍了如何在不使用Web表单控件webBrowser1的情况下发布值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi
I'm sending values to the form at this link
推荐答案
...
using System.Net;
using System.IO;
...
private void SubmitData()
{
//This is kind of a Login Script..
try
{
string user = textBox1.Text;
string pass = textBox2.Text;
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "user=" + user + "&pass=" + pass;
//In the above line the Name and value is set
byte[] data = encoding.GetBytes(postData);
WebRequest request = WebRequest.Create("http://codeproject.com/login.php");//This is the webpage
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
WebResponse response = request.GetResponse();
stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string Result = sr.ReadToEnd();
if(Result == "true")
{
MessageBox.Show("The Login was Successful.");
}
else
{
MessageBox.Show("The Login was NOT Successful.");
}
sr.Close();
stream.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
}
}
PHP代码:
PHP Code:
<?php
if(isset(
这篇关于如何在不使用Web表单控件webBrowser1的情况下发布值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!