Web Api初接触

来源:互联网 发布:宇宙巨校闪级生 知乎 编辑:程序博客网 时间:2024/06/15 10:38

在 ASP.NET Web API(一):使用初探,GET和POST数据 一文中,跟着接触了一下Web Api,照着教程,竟然也顺利可以用了,感觉蛮好的,哈哈哈。。

程序刚开始运行的时候,会在浏览器里弹出:localhost:30384

1、想要GET的话,将其改为localhost:30384/api/Users 就可以了,结果如下:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ArrayOfUsers xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MvcApplication1.Models">
<Users>
<UserEmail>Superman@cnblogs.com</UserEmail>
<UserID>1</UserID>
<UserName>Superman</UserName>
</Users>
<Users>
<UserEmail>Spiderman@cnblogs.com</UserEmail>
<UserID>2</UserID>
<UserName>Spiderman</UserName>
</Users>
<Users>
<UserEmail>Batman@cnblogs.com</UserEmail>
<UserID>3</UserID>
<UserName>Batman</UserName>
</Users>
</ArrayOfUsers>

2、POST

这样的话,需要下载Fiddler,原链接里也有下载链接(Fiddler下载地址),问题主要有2个:

(1)Request Headers里那里,我照着评论修改了一下:User-Agent: Fiddler
Host: localhost:30384
Content-Type: text/json; charset=utf-8 
Content-Length: 63

(2)Request body那里:

{"UserID":4,"UserName":"Parry","UserEmail":"Parry@cnblogs.com"}

之前复制作者贴出来的东西,Parry@cnblogs.com这里没有用“”括起来,改好点Execute就真的跳到了断点那里,而且执行都OK。。。

谢谢各位,略略知道Web API是个什么东西了,感谢。。。。


原创粉丝点击