我想在C#中使用HttpWebRequest或WebRequest调用JavaScript函数。我不想使用可以调用invokemember的webbrowser。如何使用C#上的参数调用JavaScript函数
这里是我的代码:
public void MyWebRequest(string url, string method, string data)
{
request = WebRequest.Create(url);
if (method.Equals("GET") || method.Equals("POST"))
{
// Set the Method property of the request to POST.
request.Method = method;
}
else
{
throw new Exception("Invalid Method Type");
}
string postData = data;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
}
MyWebRequest("http://example.com", "POST", "javascript:onclick=\"try(1,3)\"");
try
是一个JS函数有两个int参数。我想调用onclick方法,但是如何将参数传递给函数。
onclick="try(1,3);"
对不起,我编辑了我的代码!我忘了添加一些代码..现在它确定 – unbalanced 2012-04-25 13:36:36
JavaScript函数驻留在您使用'WebRequest'获取的页面上? – 2012-04-25 13:37:01
是它的.... :) – unbalanced 2012-04-25 13:39:32