private void button1_Click(object sender, EventArgs e)
{
request;
}
严重性代码描述项目文件行不显示状态错误CS0201入口,调用,增加,减少和新对象表达式只能用作语句。
如何调用方法并修复此问题?
>
专用无效请求
private void request(object sender, EventArgs e)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://crest-safe.azurewebsites.net/users/checkpayment/vouchers?token=mainBackup&apiKey=pds3583e");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = JsonConvert.SerializeObject(new User("cultureLand", pin));
streamWriter.Write(json);
}
}
您没有以正确的方式调用方法。 替换button1_Click()方法的以下代码:
private void button1_Click(object sender, EventArgs e)
{
request(null,null);
}
您可以将null值作为“sender”和“e”参数发送,因此该方法将毫无问题地执行。