------------------------------第一种---------------------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进行提交,怎么接收返回的结果?
谢谢各位,帮忙下了 。分多多,呵呵。
在线,等答疑。
//创建请求
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进行提交,怎么接收返回的结果?
谢谢各位,帮忙下了 。分多多,呵呵。
在线,等答疑。
解决方案 »
- C# tcpclient新手求教
- 求C#获取远程xml文件,并用dataset绑定,支持分页的代码
- 请问知道的朋友,如何转化byte赋值
- 关于数据库的操作,应该说有点难度~~~
- 正则高手帮个忙!如何写这个正则表达式?
- 请教有经验的高手了
- 问一下,怎么把excel文件读到datset里面
- 100分!!!!求一个关于算法方面的问题
- http://expert.csdn.net/Expert/topic/1873/1873786.xml?temp=.671673
- 求助!如何使用C#通过PID查关互斥
- c#(WinForm)如何让DataGridView在最后一行增加合计功能?
- Microsoft.VisualStudio.SourceSafe.Interop.dll中的get_VSSItem方法用法
WebClient.UploadValues
比HttpWebRequest 高级点
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;
}
給你個參考
呵呵 我这个版本低,没有webclient,怎么办刚看了下,用form提交的有个隐藏的input,如果模拟的话,怎么添加这个隐藏
这个怎么赋值?
// 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();
}