【http】http/1.1 八种请求方式
OPTIONS
返回服务器针对特定资源所支持的HTTP请求方法。也可以利用向Web服务器发送'*'的请求来测试服务器的功能性。
HEAD
向服务器索要与GET请求相一致的响应,只不过响应体将不会被返回。这一方法可以在不必传输整个响应内容的情况下,就可以获取包含在响应消息头中的元信息。
GET
向特定的资源发出请求。注意:GET方法不应当被用于产生“副作用”的操作中。
POST
向指定资源提交数据进行处理请求(例如提交表单或者上传文件)。数据被包含在请求体中。POST请求可能会导致新的资源的建立和/或已有资源的修改。
PUT
向指定资源位置上传其最新内容。
DELETE (后台需要实现逻辑)
请求服务器删除Request-URI所标识的资源。(后台需要有实现逻辑)
TRACE
回显服务器收到的请求,主要用于测试或诊断。
CONNECT
HTTP/1.1协议中预

MVC4 webapi实例 post delete put get 就当增删改查来用吧
public class ComplexTypeValuesController : ApiController
{ static readonly MoviesRepository repository = new MoviesRepository(); // GET api/values
public IEnumerable<Movie> Get()
{
return repository.Movies;
} // GET api/values/5
public IHttpActionResult Get(int id)
{
Movie repMovie = repository.Movies.Where(m => m.ID == id).SingleOrDefault();
if (repMovie == null)
return NotFound();
else
return Ok(repMovie);
} /*
Post this JSON object will cause cross-field validation error from IValidatableObject: {
"Title": "Fifty Shades of Grey",
"ReleaseDate": "2015-02-13T00:00:00",
"Genre": "Family",
"Price": 15.99,
"Rating": "R",
"Stars": 5
} */
// POST api/values
public IHttpActionResult Post(Movie movie)
{
if (!ModelState.IsValid)
return BadRequest(ModelState); int? maxId = (from m in repository.Movies
orderby m.ID descending
select m.ID).FirstOrDefault(); Movie newMovie = new Movie
{
ID = (maxId != null) ? (int)maxId + : ,
Title = movie.Title,
ReleaseDate = movie.ReleaseDate,
Genre = movie.Genre,
Rating = movie.Rating,
Price = movie.Price
}; repository.Movies.Add(newMovie);
return Ok(newMovie);
} // PUT api/values/5
public IHttpActionResult Put(int id, Movie movie)
{
if (!ModelState.IsValid)
return BadRequest(ModelState); var repMovie = (from m in repository.Movies
where m.ID == id
select m).SingleOrDefault(); if (repMovie == null)
return NotFound();
else
{ repMovie.Title = movie.Title;
repMovie.ReleaseDate = movie.ReleaseDate;
repMovie.Genre = movie.Genre;
repMovie.Rating = movie.Rating;
repMovie.Price = movie.Price;
return Ok(repMovie);
} } // DELETE api/values/5
public IHttpActionResult Delete(int id)
{
var repMovie = (from m in repository.Movies
where m.ID == id
select m).SingleOrDefault(); if (repMovie == null)
return NotFound();
else
{
repository.Movies.Remove(repMovie);
return Ok();
}
}
}
js 调用部分:
///////////////////////////////
// Simple Type $("#GetAllRequest").click(function (e) { $.ajax({
url: "/api/values",
type: "GET",
dataType: "json" // aka Accept
})
.done(function (data, textStatus, jqXHR) {
$('#GetAlloutput').html(data);
})
.fail(function (jqXHR, textStatus, errorThrown) {
$('#GetAlloutput').html('Bummer: there was an error: ' + textStatus);
});
}); $("#GetIdRequest").click(function (e) { $.ajax({
url: "/api/values/42",
type: "GET",
dataType: "json" // aka Accept
})
.done(function (data, textStatus, jqXHR) {
$('#GetIdoutput').html(data);
})
.fail(function (jqXHR, textStatus, errorThrown) {
$('#GetIdoutput').html('Bummer: there was an error: ' + textStatus);
}); }); $("#PostRequest").click(function (e) { $.ajax({
url: "/api/values",
type: "POST",
dataType: "json", // aka Accept
contentType: "application/json",
data: "\"myData\""
})
.done(function (data, textStatus, jqXHR) {
$('#Postoutput').html(data);
})
.fail(function (jqXHR, textStatus, errorThrown) {
$('#Postoutput').html('Bummer: there was an error: ' + textStatus);
});
}); $("#PutRequest").click(function (e) { $.ajax({
url: "/api/values/42",
type: "PUT",
dataType: "json", // aka Accept
contentType: "application/json",
data: "\"myData\""
})
.done(function (data, textStatus, jqXHR) {
$('#Putoutput').html(data);
})
.fail(function (jqXHR, textStatus, errorThrown) {
$('#Putoutput').html('Bummer: there was an error: ' + textStatus);
}); }); $("#DeleteRequest").click(function (e) { $.ajax({
url: "/api/values/42",
type: "DELETE",
dataType: "json", // aka Accept
contentType: "application/json"
})
.done(function (data, textStatus, jqXHR) {
$('#Deleteoutput').html(data);
})
.fail(function (jqXHR, textStatus, errorThrown) {
$('#Deleteoutput').html('Bummer: there was an error: ' + textStatus);
});
});
【http】http/1.1 八种请求方式的更多相关文章
- http 中定义的八种请求的介绍
在http1.1协议中,共定义了8种可以向服务器发起的请求(这些请求也叫做方法或动作),本文对这八种请求做出简要的介绍: 1.PUT:put的本义是推送 这个请求的含义就是推送某个资源到服务器,相当于 ...
- Ajax中的get和post两种请求方式的异同
Ajax中我们经常用到get和post请求.那么什么时候用get请求,什么时候用post方式请求呢? 在做回答前我们首先要了解get和post的区别. 1. get是把参数数据队列加到提交表单的A ...
- HttpwebClient的四种请求方式
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷. 本文旨在发布代码,供自己参考,也供大家参考,谢谢. 正题: Ht ...
- Ajax的get和post两种请求方式区别
Ajax的get和post两种请求方式区别 (摘录):http://ip-10000.blog.sohu.com/114437748.html 解get和post的区别. 1. get是把参数数据队列 ...
- SpringMVC的REST风格的四种请求方式
一. 在HTTP 协议里面,四个表示操作方式的动词:GET.POST.PUT.DELETE. ·它们分别对应四种基本操作: 1.GET ====== 获 取资源 2.POST ======新建资源 ...
- 【转载】Redis的Java客户端Jedis的八种调用方式(事务、管道、分布式…)介绍
转载地址:http://blog.csdn.net/truong/article/details/46711045 关键字:Redis的Java客户端Jedis的八种调用方式(事务.管道.分布式…)介 ...
- 【spring springmvc】这里有你想要的SpringMVC的REST风格的四种请求方式
概述 之前的文章springmvc使用注解声明控制器与请求映射有简单提到过控制器与请求映射,这一次就详细讲解一下SpringMVC的REST风格的四种请求方式及其使用方法. 你能get的知识点 1.什 ...
- HTTP协议八种请求类型介绍
HTTP 协议中共定义了八种方法或者叫“动作”来表明对 Request-URI 指定的资源的不同操作方式,具体介绍如下: OPTIONS:返回服务器针对特定资源所支持的HTTP请求方法.也可以利用向W ...
- jQuery中的Ajax几种请求方式
1. load( url, [data], [callback] ) :载入远程 HTML 文件代码并插入至 DOM 中. url (String) : 请求的HTML页的URL地址. data (M ...
随机推荐
- Frameset使用教程 小结
frame,是网页开发必须掌握的知识.例如后台架构.局部刷新,页面分割,都是frame的用途表现,尤其是后台页面制作,使用frame会给用户带来非常舒适的使用感受. frame知识点包括(frames ...
- H5入门-xhtml+css2-第01节
<!-- 声明版本号,DOCTYPE html是html5版本 --> <!DOCTYPE html> <!-- 声明网页语言 en-英文 zh-中文 zh-cn中文 - ...
- Part 13 Cast and Convert functions in SQL Server
Part 28 Cast and Convert functions in SQL Server
- DWZ (JUI) 教程 dwz框架 刷新dialog解决方案
在DWZ中进行ajax表单提交后,通过回调函数来返回状态结果,以及返回是否需要刷新父页的navTabId. DWZ给我们提供了两个回调函数,一个是子窗口为navTab的navTabAjax ...
- Warning: Permanently added '...' (RSA) to the list of known hosts --Windows下git bash 警告处理
原链接地址 StackOverflow 处理方法: 创建文件~/.ssh/config, 此处对应windows当前用户目录下的.ssh文件夹 增加如下语句 UserKnownHostsFile ~/ ...
- 15条JavaScript最佳实践很经典噢
感觉比较经典,特转载腾讯大讲堂.本文档整理大部分公认的.或者少有争议的JavaScript良好书写规范(Best Practice).一些显而易见的常识就不再论述(比如要用对象支持识别判断,而不是浏览 ...
- Github 访问时出现Permission denied (public key)
一. 发现问题: 使用 git clone 命令时出现Permission denied (public key) . 二. 解决问题: 1.首先尝试重新添加以前生成的key,添加多次,仍然不起作用. ...
- 20150506—WinForm自动生成按钮&按钮拖动
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 关于火狐浏览器不支持img onerror的办法
项目中,要使用到缺省图,除了火狐浏览器,其它浏览器都支持img onerror事件.我使用到的解决的办法就是给图片的外层标签加背景,背景图用的就是缺省图. 上代码 <img src=" ...
- poj 3268 Silver Cow Party
S ...