如何在不使用Web表单控件webBrowser1的情况下发布值? [英] How to post values without using the web form control webBrowser1?
本文介绍了如何在不使用Web表单控件webBrowser1的情况下发布值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi
I'm sending values to the form at this link
推荐答案
如果您尝试将数据从C#应用程序发布到PHP表单..
WebRequest和WebResponse可能会帮助您..
试试这个..
C#代码:
If you are trying to post data from a C# application to PHP form..
WebRequest and WebResponse Might Help you..
Try this..
C# Code:
...
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(
_POST [' user'])&& isset(
_POST['user']) && isset(
_POST [' pass']))
{
_POST['pass'])) {
这篇关于如何在不使用Web表单控件webBrowser1的情况下发布值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文