这个问题郁闷了我几个星期了~一直没得到解决的方法~
问题是这样的~最近在写一个winform(c#)向webform(asp)提交数据的程序~是通过GET方法~
以前写的都是通过POST方式~都通过了~
HTTP的头信息都伪造好了~就是提交不上去~
string GetMsg = "Msg=我爱你";
WebClient MyWebClient = new WebClient();
MyWebClient.Headers.Add("Accept", "image/gif,image/x-xbitmap,image/jpeg,image/pjpeg,application/x-shockwave-flash,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/msword,*/*");
MyWebClient.Headers.Add("Accept-Language", "zh-cn");
MyWebClient.Headers.Add("Accept-Encoding", "gzip, deflate");
MyWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
richTextBox1.Text = MyWebClient.UploadString("http://ydsoft.xd2.cn/download/get.asp","GET", GetMsg);通过查阅MSDN知道UploadString方法重载了4次~但没有一次里面提到GET方式~
各位给我思路~谢谢~
问题是这样的~最近在写一个winform(c#)向webform(asp)提交数据的程序~是通过GET方法~
以前写的都是通过POST方式~都通过了~
HTTP的头信息都伪造好了~就是提交不上去~
string GetMsg = "Msg=我爱你";
WebClient MyWebClient = new WebClient();
MyWebClient.Headers.Add("Accept", "image/gif,image/x-xbitmap,image/jpeg,image/pjpeg,application/x-shockwave-flash,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/msword,*/*");
MyWebClient.Headers.Add("Accept-Language", "zh-cn");
MyWebClient.Headers.Add("Accept-Encoding", "gzip, deflate");
MyWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
richTextBox1.Text = MyWebClient.UploadString("http://ydsoft.xd2.cn/download/get.asp","GET", GetMsg);通过查阅MSDN知道UploadString方法重载了4次~但没有一次里面提到GET方式~
各位给我思路~谢谢~
2.0
的吗?
如果有这样的方法,我估计GetMsg应该是一个 abc=adfadf这样的querystring吧
对是2。0~GETMSG~就是你要传递的字符串~
因为是GET方式所以不需要象POST方式一样转成数组~
TO~hdt(倦怠)
不好意思没装MSDN~麻烦你贴下代码~谢谢
using System.Net;
using System.IO;
using System.Text;
namespace webgetcs
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
string strurl = @"http://sms.61xy.com:8088/send/send.aspx?mobile=13564250347&mobile_spid=huangrongfang&mobile_ip=127.0.0.1&mobile_sp=3210G&mobile_from=http://www.test.com";
Console.WriteLine(getPage(strurl));
Console.ReadLine();
}
public static string getPage(String url)
{
string strResult = ""; try
{
// Create a 'WebRequest' object with the specified url. WebRequest myWebRequest = WebRequest.Create(url);
myWebRequest.Timeout=10000;
// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse();
// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = myWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
// Pipe the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( ReceiveStream, encode );
char[] read = new char[256];
// Read 256 charcters at a time.
int count = readStream.Read( read, 0, 256 );
while (count > 0)
{
// Dump the 256 characters on a string and display the string onto the console.
String str = new String(read, 0, count);
strResult = strResult + str;
count = readStream.Read(read, 0, 256);
}
// Release the resources of stream object.
readStream.Close();
// Release the resources of response object.
myWebResponse.Close();
}
catch(Exception e)
{
strResult = strResult+e.ToString();
} return strResult;
}
}}
谢谢了各位了~