简体   繁体   English

如何在 postman 的 post 请求正文中传递字符串

[英]How to pass string in post request body in postman

I have an POST API end point, ie我有一个 POST API 端点,即

[Route("api/{parameter1}/employee")]
[HttpPost]
public Employee RegisterEmployee(string parameter1, [FromBody] string parameter2)

Now, I want to hit this API from postman.现在,我想从 postman 中找到这个 API。

My request URL is:我的要求 URL 是:

http://localhost:xxxxx/api/parameter1/employee

And the body is:身体是:

在此处输入图像描述

So, in this way i am getting: 415 Unsupported Media Type error.所以,通过这种方式我得到:415 Unsupported Media Type 错误。

If i try other ways then i am able to hit the API, but parameter2 is always coming as null .如果我尝试其他方式,那么我可以点击 API,但参数 2 总是以 null 的形式出现

So, how should i pass the parameter2 value in postman?那么,我应该如何传递 postman 中的 parameter2 值?

Try setting content type to application/json .尝试将内容类型设置为application/json JSON String inputs thankfully capture as strings in ASP.NET Core. JSON 字符串输入幸运地在 ASP.NET 内核中捕获为字符串。

在此处输入图像描述

Alternatively, you could read the body string from the request stream:或者,您可以从请求 stream 中读取正文字符串:

using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{  
    return await reader.ReadToEndAsync();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM