[英]how to pass hardcoded guid in postman body section
您應該使用 static 方法Guid.NewGuid()
而不是調用默認構造函數。 這應該有效:
var ApplicationId = Guid.NewGuid();
var DistrictId = Guid.NewGuid();
JSON中沒有GUID數據類型,不能直接使用。
相反,您可以在 model 中將參數的數據類型用作“字符串”。
然后:
解決方案 1
或者,您可以將參數定義為字符串,然后在您的方法中將它們轉換為 GUID:
public class AuthenticateModel
{
//...
public string ApplicationId { get; set; }
public string DistrictId { get; set; }
//...
}
在你的方法中:
public SecurityToken AuthenticateUser(AuthenticateModel authenticateModel)
{
var applicationId = Guid.Parse(authenticateModel.ApplicationId);
var districtId = Guid.Parse(authenticateModel.DistrictId);
}
解決方案 2:
您可以創建 2 個新變量:
public class AuthenticateModel
{
public string ApplicationId { get; set; }
public string DistrictId { get; set; }
[JsonIgnore] //this is for Newtonsoft.Json
[IgnoreDataMember] //this is for default JavaScriptSerializer class
public Guid ApplicationGuid { get => Guid.Parse(ApplicationId); set => ApplicationId = value.ToString(); }
[JsonIgnore] //this is for Newtonsoft.Json
[IgnoreDataMember] //this is for default JavaScriptSerializer class
public Guid DistrictGuid { get => Guid.Parse(DistrictId); set => DistrictId = value.ToString(); }
}
然后在你的方法中使用它:
public SecurityToken AuthenticateUser(AuthenticateModel authenticateModel)
{
//...
doSomething(authenticateModel.ApplicationGuid);
doSomething(authenticateModel.DistrictGuid);
//...
}
希望對你有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.