如何在c#中post参数给一个php页面
我有一个OA系统(net开发),和一个bbs(php)系统,我想实现登录OA后,点一个链接直接进入bbs,bbs就不需登录了,这就需要通过C#把用户名和密码传到bbs首页上,,现在我实现了能打开论坛首页,可是路径却是本地的,哪位高手指点。代码如下:
WebClient myWebClient = new WebClient();
string strUrl = "http://bbs.handinfo.cn/login.php ";
string postData = "username=ally&password=12345&login=登录 ";
byte[] byteArray;
byte[] responseArray;
WebHeaderCollection myWebHeaderCollection;
myWebClient.Headers.Add( "Content-Type ", "application/x-www-form-urlencoded ");
myWebClient.Headers.Add( "Accept-Language ", "zh-cn ");
myWebHeaderCollection = myWebClient.Headers;
byteArray = Encoding.ASCII.GetBytes(postData);
try
{
responseArray = myWebClient.UploadData(strUrl, "POST ",byteArray);
//接收正文信息;
//Response.Write(Encoding.Default.GetString(responseArray));
//Response.Write(Encoding.GetEncoding( "GB2312 ").GetString(responseArray));
//string str = System.Text.Encoding.GetEncoding( "gb2312 ").GetString(b);
// Response.Write(Encoding.UTF8.GetString(responseArray));
System.IO.Stream writer = req.GetRequestStream();//获得请求流
writer.Write(Encoding.UTF8.GetString(responseArray, 0, Encoding.UTF8.GetString(responseArray.Length));//将请求参数写入流
writer.Close();//关闭请求流
}
catch(Exception ex)
{
throw new Exception( "出错: "+ex.Message);
}
------解决方案-------------------- <script language= "javascript " type= "text/javascript ">
var chinaweb = "http://bbs.php.com ";
function Connect()
{
try
{
var action = chinaweb;
var formQuery = document.createElement( " <form action= ' "+action+ " ' method= 'post ' target= '_blank '> </form> ");
var inputHidden = document.createElement( " <input type= 'hidden ' name= 'username '> ");
inputHidden.value = 'username ';
var inputPwd = document.createElement( " <input type= 'hidden ' name= 'password '> ");
inputPwd .value = 'pwd ';
formQuery.appendChild(inputPwd );
document.body.appendChild(