Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. [HttpPost]
  2. public async Task<IHttpActionResult> Test(string name)
  3. {
  4. int i = 0;
  5. i = i + 1;
  6. return Ok();
  7. }
  8.  
  9. POST http://localhost:8089/api/MyApiController/test
  10.  
  11. John
  12.  
  13. POST http://localhost:8089/api/MyApiController/test HTTP/1.1
  14. User-Agent: Fiddler
  15. Host: localhost:8089
  16. Content-Length: 26
  17. Content-Type: application/json; charset=utf-8
  18.  
  19. { "name" : "John"}
  20.  
  21. HTTP/1.1 405 Method Not Allowed
  22. Cache-Control: no-cache
  23. Pragma: no-cache
  24. Allow: GET
  25. Content-Type: application/json; charset=utf-8
  26. Expires: -1
  27. Server: Microsoft-IIS/8.0
  28. X-SourceFiles: =?UTF-8?B?QzpcRWNvZmljXFNvbGlkUVxKTExcamxsLW1hcmtldHNwaGVyZVxXZWJzaXRlXGFwaVxTZWFyY2hBcGlcaW5kZXg=?=
  29. X-Powered-By: ASP.NET
  30. Date: Fri, 12 Dec 2014 15:51:50 GMT
  31. Content-Length: 73
  32.  
  33. {"Message":"The requested resource does not support http method 'POST'."}
  34.  
  35. var content = await Request.Content.ReadAsStringAsync();
  36.  
  37. http://localhost:8089/api/MyApi/test
  38.  
  39. config.Routes.MapHttpRoute(
  40. name: "DefaultApi1",
  41. routeTemplate: "api/{controller}/{action}",
  42. defaults: new { action="test" }
  43. );
  44.  
  45. [HttpPost]
  46. public async Task<IHttpActionResult> Test([Frombody]string name)
  47. {
  48. int i = 0;
  49. i = i + 1;
  50. return Ok();
  51. }
  52.  
  53. { "name" : "somtext"}
  54.  
  55. public async Task<IHttpActionResult> Post( [ FromBody ] **object** items )
  56. {
  57. Console.WriteLine( items );
  58. return Ok();
  59. }
  60.  
  61. { "name" : "John" }
  62.  
  63. `POST http://localhost:8089/api/MyApiController/`
  64. User-Agent: Fiddler
  65. Host: localhost:8089
  66. Content-Length: 26
  67.  
  68. { "name" : "John" }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement