0

嗨,我正在尝试发布一个类似的对象:

    public class myobj
{
public string name {get;set;}
public myEntity myentity {get;set;}
public mySecondEntity mySecondEntity {get;set;}

}

public class myEntity {get;set;}
{
public string name {get;set;}
public string description {get;set;}
}

public class mySecondEntity {get;set;}
{
public string name {get;set;}
public string description {get;set;}
}

当我使用生成 myObj 的新对象并使用 PostUrlEncodedAsync 时,它会将其发布为:

 name : "myname",
 myentity : "detex.Models.DTO.myEntity",
 mysecondentity : "detex.Models.DTO.mySecondEntity 

不确定我的命名空间/类在这些字段中做了什么。我将其发布为等待“myurl.com”.PostUrlEncodedAsync(_model)。

4

1 回答 1

0

Flurl assumes that objects passed to PostUrlEncodedAsync represent simple name/value pairs. It simply does a ToString on your values, which is why you're getting detex.Models.DTO.myEntity. Do you want those values serialized to JSON? If so you'll need to do that yourself:

"myurl.com".PostUrlEncodedAsync(new {
    name = _model.name,
    myentity = JsonConvert.SerializeObject(_model.myentity),
    mysecondentity = JsonConvert.SerializeObject(_model.mySecondEntity)
});

Posting complex objects as URL-encoded is not typical, which is why serializing those values is not built into Flurl.

于 2016-03-07T16:01:48.750 回答