0

I'm trying to send a URL as content from my client to my web api.
I don't want to encode it, so I'm sending it in the body as JSON.

Sending the JSON as

"{"URL":"https://www.example.com/s/otherdetail"}"

If I use method signature

[HttpPost("UploadURL/{SpecID}/{DocType}")]
public ActionResult<string> UploadSpecsURL(int SpecID, string DocType, [FromBody] JsonElement body) {
    string json = System.Text.Json.JsonSerializer.Serialize(body);

then I get content

body = ValueKind = Object : "{"URL":"https://www.example.com/s/otherdetail"}"
json = "{\"URL\":\"https://www.example.com/s/otherdetail\"}"

but if I try to define my own type to receive the content

public struct URLpacket {
    public string URL;
}

[HttpPost("UploadURL/{SpecID}/{DocType}")]
public ActionResult<string> UploadSpecsURL(int SpecID, string DocType, [FromBody] URLpacket packet) {

I don't get an error, but the URL is null.

1 Answer 1

1

you have to add getters setters to your class

public struct URLpacket {
    public string URL { get; set; }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.