使用RestSharp运行多个GET请求,但它只运行一个请求然后停止
我正在尝试使用 RestSharp 运行多个 GET 请求,但它只运行一个请求,然后停止。有人可以建议我在这里做错了什么吗?
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RestSharp;
namespace CertificatesAPI
{
[TestClass]
public class UnitTest2
{
[TestMethod]
public static void Reqres()
{
int[] userIDs = {1, 2, 3, 4, 5};
foreach (int ID in userIDs)
{
var client = new RestClient("https://reqres.in/api/users");
var request = new RestRequest(Method.GET);
request.AddParameter("id", ID);
IRestResponse response = client.Execute(request);
HttpStatusCode statusCode = response.StatusCode;
int StatusCode = (int)statusCode;
if (StatusCode == 200)
{
Console.WriteLine("SUCCESS");
Console.WriteLine(response.Content);
}
else
{
Console.WriteLine("Status Code: " + StatusCode);
}
Console.Read();
}
}
}
}
我在 Visual Studio 中创建了一个单元测试项目,然后在同一解决方案中创建了另一个项目来调用此方法 Reqres 并在 Main 方法下运行它。我是一名后端测试人员,也是 C# 和 Visual Studio 的新手。
I am trying to run multiple GET requests using RestSharp but it only runs one request and then stop. Can someone please suggest what I am doing wrong here?
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RestSharp;
namespace CertificatesAPI
{
[TestClass]
public class UnitTest2
{
[TestMethod]
public static void Reqres()
{
int[] userIDs = {1, 2, 3, 4, 5};
foreach (int ID in userIDs)
{
var client = new RestClient("https://reqres.in/api/users");
var request = new RestRequest(Method.GET);
request.AddParameter("id", ID);
IRestResponse response = client.Execute(request);
HttpStatusCode statusCode = response.StatusCode;
int StatusCode = (int)statusCode;
if (StatusCode == 200)
{
Console.WriteLine("SUCCESS");
Console.WriteLine(response.Content);
}
else
{
Console.WriteLine("Status Code: " + StatusCode);
}
Console.Read();
}
}
}
}
I created a Unit Test Project in Visual Studio and then created another project in the same solution to call this method Reqres and run this under Main method. I am a backend tester and new to C# and Visual Studio.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论