发布的数据asp.net的Web API

编程入门 行业动态 更新时间:2024-10-23 13:27:08
本文介绍了发布的数据asp的Web API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图找出新的ASP.NET Web API。

I'm trying to figure out the new ASP.NET Web API.

到目前为止,我已经能够创建此方法的签名,并连接到它只是罚款,并得到有效的回应...

So far I've been able to create this method signature and connect to it just fine and get a valid response...

[HttpPost] public HttpResponseMessage CreateAccount()

我能请求发送给此方法与小提琴手,并已验证其收到了请求。

I am able to send a request to this method with fiddler and have verified that it is receiving the request.

然而,当我试图通过数据是,当我遇到一个问题。

However, when I try to pass data is when I am running into a problem.

我想的第一件事就是...

The first thing I tried was...

[HttpPost] public HttpResponseMessage CreateAccount([FromBody]string email, [FromBody]string password)

和我键入

电子邮件:XYZ,密码:ABC

email:xyz,password:abc

成小提琴手请求的主体。当我这样做,我得到一个500错误,指出

into the body of the request in fiddler. When I do this I get a 500 error stating

无法绑定多个参数(电子邮件和密码),以请求的内容。

'Can't bind multiple parameters ('email' and 'password') to the request's content.'

我也试过这是一个方法的签名...

I have also tried this as a method signature...

[HttpPost] public HttpResponseMessage CreateAccount([FromBody]UserAccountRequestData data)

与UserAccountRequestData是一个简单的POCO

with the UserAccountRequestData being a simple POCO

public class UserAccountRequestData { public string Email { get; set; } public string Password { get; set; } }

和我把

{电子邮件:XYZ,密码:ABC}

{Email:xyz,Password:abc}

数据:{电子邮件:XYZ,密码:ABC}

data:{Email:xyz,Password:abc}

入请求的主体。在这两种情况下,试图填充POCO我能够在调试时到达的方法,但数据对象总是空。

into the body of the request. In both cases trying to populate the POCO I am able to reach the method while debugging, but the data object is always null.

我需要了解如何创建接受API方法均强类型波苏斯和其他接受多个原始类型,如字符串和整数。

I need to understand how to create API methods that accept both strongly typed POCOs and others that accept multiple primitive types like strings and ints.

感谢

推荐答案

您需要设置内容类型头应用程序/ JSON ,然后提供有效的JSON。

You need to set the Content-Type header to application/json and then provide valid JSON.

{"Email":"xyz","Password":"abc"}

更多推荐

发布的数据asp.net的Web API

本文发布于:2023-11-16 09:37:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603107.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   asp   net   Web   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!