c#传递winform窗体中的文本框的值到服务器
c#传递winform窗体中的文本框的值到服务器,服务器是php文件接收,winfrom窗体有两个文本框用户名和密码,传递到服务器,判断用户名和密码是否正确,并返回一个值...
c#传递winform窗体中的文本框的值到服务器,服务器是php文件接收,winfrom窗体有两个文本框用户名和密码,传递到服务器,判断用户名和密码是否正确,并返回一个值。求大神指教,写出代码,小弟菜鸟一只。
展开
推荐于2016-06-22 · 知道合伙人软件行家
关注
展开全部
System.Net.ServicePointManager.Expect100Continue = false;
Console.WriteLine("正在请求网关验证服务...");
CookieContainer cc = new CookieContainer();
string postData = "username=XXXX&userpwd=XXXX&login=参数值其他";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://你的HTTP路径在这里"));
request.CookieContainer = cc;
request.Method = "POST";
request.Accept = "text/html, application/xhtml+xml, */*";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko";
request.AllowAutoRedirect = true;
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close();
Console.WriteLine("正在解析网关响应...");
HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.Default);
string text2 = sr2.ReadToEnd();
if (text2.IndexOf("window.location") > -1)
{
Console.WriteLine("网关注册成功!");
}
Console.WriteLine("正在请求网关验证服务...");
CookieContainer cc = new CookieContainer();
string postData = "username=XXXX&userpwd=XXXX&login=参数值其他";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://你的HTTP路径在这里"));
request.CookieContainer = cc;
request.Method = "POST";
request.Accept = "text/html, application/xhtml+xml, */*";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko";
request.AllowAutoRedirect = true;
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close();
Console.WriteLine("正在解析网关响应...");
HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.Default);
string text2 = sr2.ReadToEnd();
if (text2.IndexOf("window.location") > -1)
{
Console.WriteLine("网关注册成功!");
}
追答
http://localhost/hdjy/index.php/Admin/login/index。 看你这个接口是如何定义的,
如果是POST方式接收,那按我的写法
string postData = "username=XXXX&userpwd=XXXX&login=参数值其他";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化
如果是GET方式接收数据,
那可以直接放在 URL上如http://localhost/hdjy/index.php/Admin/login/index?username=xxx&pwd=fdsa
追问
求您的qq,我的是1274218078
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询