C# で HttpWebRequest または WebRequest を使用して 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
2 つの int パラメーターを持つ JS 関数です。onclick メソッドを呼び出したいのですが、関数にパラメータを渡すにはどうすればよいですか。
onclick="try(1,3);"