【发布时间】:2020-11-15 09:41:47
【问题描述】:
这是我的代码
public static RestRequest CreateReportRequest()
{
restRequest = new RestRequest(Method.POST);
restRequest.AddHeader("Content-Type", "application/json");
restRequest.AddHeader("Authorization", "Basic T1NUAxNFVxeTIwag==");
using (StreamReader file =
File.OpenText(@"C:\Automation\APIAutomationSuite\APIAutomationSuite\TestData\CreateReport.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject Body = (JObject)JToken.ReadFrom(reader);
}
restRequest.AddJsonBody(Body);
var response = client.Execute(restRequest);
return restRequest;
}
当我调试代码时,我在“JObject Body”中看到 json 请求正文值,但是当按 F10 并移动到下一条语句 (restRequest.AddJsonBody(Body);) 时,正文值变为空。这会引发错误的请求错误。 请帮我解决这个问题。
【问题讨论】:
-
在 using 语句之外声明“JObject Body”。它可能会失去作用域
标签: c# visual-studio api automation