我有一个关于循环按钮点击事件的问题,我尝试了很多方法并搜索了许多页面以寻找过去一小时的简单答案,但事实是每个答案看起来都像外星人的代码,可能是因为我还在发展的新手.
这是我正在尝试做的简化版本:
private string Message = "Hello";
private void Spam(bool loop)
{
if (loop == true)
{
while (loop == true)
{
MessageBox.Show(Message);
}
}
else { MessageBox.Show("Spamming has stopped !! "); }
}
private void button1_Click(object sender, EventArgs e)
{
Spam(true);
}
private void button2_Click(object sender, EventArgs e)
{
Spam(false);
}
Run Code Online (Sandbox Code Playgroud)
显然这不是我的API,或者它是一个无用的东西发明,但是,代码本身很长并且你们总是要求"相关代码"(没有不尊重),所以就是这样.
我的问题:单击按钮2时打破垃圾邮件循环,我的代码看起来足够让API可以搞清楚,但每次点击按钮1时,API都会冻结.
我想使用 RestSharp 将数据发布到我的 API:
我的结构是这样的:
在 PostMan 中,我使用正文选项和原始输入,如下所示:
{
"story_code" : "Amazing Pillow 2.0",
"master_code" : "199",
"created" : "2018-06-01 00:35:07"
}
Run Code Online (Sandbox Code Playgroud)
它有效。在 RestSharp 中,我使用了这段代码,但它返回了错误请求和消息:“无法创建产品。数据不完整。”
var client = new RestClient("http://api.dastanito.ir");
var request = new RestRequest("/storiesmaster/creat.php", Method.POST);
request.AddParameter("story_code", "value");
request.AddParameter("master_code", "value2");
IRestResponse response = client.Execute(request);
var content = response.Content;
Run Code Online (Sandbox Code Playgroud)
我什至使用了 AddQueryParameter 但又是错误的请求。
我应该使用什么功能?