------------------------------第一种---------------------error------------------------------------这个是我命令按钮中的click事件代码: 
//创建请求  
            string  ls_url="https://ibsbjstar.ccb.com.cn/app/ccbMain?MERCHANTID=105584045110001&BRANCHID=442000000&POSID=100000088&ORDERDATE=20090501&BEGORDERTIME=00:00:00&ENDORDERTIME=23:59:59&BEGORDERID=&ENDORDERID=&QUPWD=&TXCODE=410405&SEL_TYPE=3&OPERATOR=&MAC=46fd6686d97377852f1a914423a819a6";            HttpWebRequest httpRequest = (HttpWebRequest) HttpWebRequest.Create(ls_host);;
          // httpRequest.UserAgent="MSIE"; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
            httpRequest.UserAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
httpRequest.Method="POST"; 
          //  httpRequest.ContentType="multipart/form-data";application/x-www-form-urlencoded
 httpRequest.ContentType="application/x-www-form-urlencoded";
if (httpRequest == null) 

throw new ApplicationException( string.Format("Invalid url string: {0}", ls_host) ); 
}   
            httpRequest.ContentLength = bs.Length;     
using (Stream reqStream = httpRequest.GetRequestStream())
{
reqStream.Write(bs, 0, bs.Length);
reqStream.Close();
}
            
#region 发送post请求到服务器并读取服务器返回信息
Stream responseStream; 
WebResponse   wresp=httpRequest.GetResponse();   
try 
{   
responseStream = wresp.GetResponseStream(); 

catch(Exception eee) 
{  
Console.WriteLine( 
string.Format("POST操作发生异常:{0}", eee.Message+ eee.StackTrace+eee.HelpLink+eee.ToString())  ); 
throw eee; 

#endregion 现在这样的错误出现在:using (Stream reqStream = httpRequest.GetRequestStream())
异常详细信息: System.Net.WebException: 远程服务器返回错误: (500) 内部服务器错误。
------------------------------第二种用js提交form------------------ok-----------------------------------  window.MD5form.method="post";
    window.MD5form.action=window.MD5form.bankURL.value; --和上面的串是一样的地址
    window.MD5form.submit();  --提交后返回一个xml结果页面------------------------------问题------------------??--------------------------------
1.  第一种错误在那个地方,怎么解决?
2.  http://msdn.microsoft.com/en-us/library/y0hedwet(zh-cn,VS.80).aspx ;这个参考下,我不知具体怎么操作
3.  如果用第二种js进行提交,怎么接收返回的结果?
     谢谢各位,帮忙下了 。分多多,呵呵。 
在线,等答疑。

解决方案 »

  1.   


    WebClient.UploadValues
    比HttpWebRequest 高级点
      

  2.   


    public string Post(string url, string content, string referer)
            {
                try
                {
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(url));
                    req.UserAgent = reqUserAgent;
                    req.CookieContainer = _cc;
                    req.Referer = referer;
                    byte[] buff = Encoding.GetEncoding("GB2312").GetBytes(content);
                    req.Method = "POST";
                    req.Timeout = _timeout;
                    req.ContentType = "application/x-www-form-urlencoded";
                    req.ContentLength = buff.Length;
                    if (null != _proxy && null != _proxy.Credentials)
                    {
                        req.UseDefaultCredentials = true;
                    }
                    req.Proxy = _proxy;
                    Stream reqStream = req.GetRequestStream();
                    reqStream.Write(buff, 0, buff.Length);
                    reqStream.Close();                //接收返回字串
                    HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                    StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
                    return sr.ReadToEnd();
                }
                catch (Exception e)
                {
                }
                return string.Empty;
            }
    給你個參考
      

  3.   

    blestcc 我穿墙而过     和我的没有什么区别,现在就是不知代理怎么设置,我们这边是没有代理的曾经真的以为人生就这样了
        呵呵 我这个版本低,没有webclient,怎么办刚看了下,用form提交的有个隐藏的input,如果模拟的话,怎么添加这个隐藏
      

  4.   

       req.CookieContainer = _cc; 
    这个怎么赋值?
      

  5.   

    string  ls_url="https://ibsbjstar.ccb.com.cn/app/ccbMain?MERCHANTID=105584045110004&BRANCHID=442000000&POSID=100000088&ORDERDATE=20090501&BEGORDERTIME=00:00:00&ENDORDERTIME=23:59:59&BEGORDERID=&ENDORDERID=&QUPWD=&TXCODE=410405&SEL_TYPE=3&OPERATOR=&MAC=46fd6686d97377852f1a914423a819a6";
    // string[] url =this.result.Value.ToString().Replace("amp;","").Split('?');   string[] url = ls_url.Split('?');
    string ls_host =url[0].ToString(); 
    string param= url[1].ToString();
    byte[] bs = Encoding.ASCII.GetBytes(param); 
      //创建请求
                HttpWebRequest httpRequest = (HttpWebRequest) HttpWebRequest.Create(ls_host);;
                httpRequest.UserAgent="MSIE";  //Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) ;
    httpRequest.Method="POST";  
     httpRequest.ContentType="multipart/form-data"; 
    if (httpRequest == null) 

    throw new ApplicationException( string.Format("Invalid url string: {0}", ls_host) ); 
    }   
                httpRequest.ContentLength = bs.Length;     
    using (Stream reqStream = httpRequest.GetRequestStream())
    {
    reqStream.Write(bs, 0, bs.Length);
    reqStream.Close();
    }