我需要在C#中使用Web客户端方法将下面的对象作为post方法的参数传递.
{
"company":
{
"id": "e63dfcab345260b2591f585126ede56627db4ef2"
},
"requestor":
{
"id": "",
"email": "customer@example.com ",
"firstName": "Test",
"lastName": "Requestor",
"role": "employerAdmin",
"phone": "(415)1112222",
"title": "HR Manager"
}
}
Run Code Online (Sandbox Code Playgroud)
我这样转换了
company[id]=e63dfcab345260b2591f585126ede56627db4ef2&requestor[id]=&requestor[email]=customer@example.com+&requestor[firstName]=Test&requestor[lastName]=Requestor&requestor[role]=employerAdmin&requestor[phone]=(415)1112222&requestor[title]=HR+Manager
Run Code Online (Sandbox Code Playgroud)
但我得到无效的参数错误.请帮我.提前致谢.
我的整个代码如下:
using (var Requestor = new System.Net.WebClient())
{
string url = "https://stormaas-pre.inflection.com:8443/v1/Requestor?";
string parameters = "company[id]='757563a3-67df-4a6e-9ef9-d89d57d41e0d'&requestor[id]=''&requestor[email]='customer@example.com'&requestor[firstName]='Test'&requestor[lastName]='Requestor'&requestor[role]='employerAdmin'&requestor[phone]='(415)1112222'&requestor[title]='HRManager'";
Requestor.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Requestor.Credentials = new System.Net.NetworkCredential("xyz:xyz!", "");
Requestor.Encoding = System.Text.Encoding.UTF8;
Requestor.Headers[HttpRequestHeader.ContentType] = "application/json";
Requestor.Headers[HttpRequestHeader.Accept] = "text/xml";
string res = Requestor.UploadString(url, "POST", parameters);
}
Run Code Online (Sandbox Code Playgroud) 我们有一个 Asp.net MVC 项目,它有超过 1000 个 ActionResult,我需要为它们全部添加一个 C# 函数来检查会话的值。那么你有什么提议来做这件事呢?下面这两行有一些我的 Controller 和 ActionResult 的例子:
public partial class CRMController : Controller
{
public ActionResult OrganizationCategory()
{
//I want add a C# function here
}
}
public partial class BaseInfoController : Controller
{
public ActionResult Lead()
{
//I Want Add a C# Function here
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试为 MVC 应用程序编写单元测试。我试图测试我的控制器是否返回正确的视图名称。
这是我测试的控制器操作:
public IActionResult Index(string reportcode)
{
if(string.IsNullOrEmpty(reportcode))
ReportCode = reportcode;
ViewBag.GridSource = GetReportData(reportcode);
return View("Index");
}
Run Code Online (Sandbox Code Playgroud)
这是我的单元测试:
[Test]
public void Index_ReturnCorrectView()
{
var controller = new HomeController();
var result = controller.Index("COMD") as ViewResult;
Assert.AreEqual("Index", result.ViewName);
}
Run Code Online (Sandbox Code Playgroud)
我从单元测试中得到的错误预期为“Index”,但为空。我做了很多搜索,大多数答案都说 ViewName 属性应该在返回视图时声明它之后设置。我尝试了同样的方法,但仍然无法正常工作。
谢谢