前臺提交數據的類型

来源:http://www.cnblogs.com/kevin2chen/archive/2017/05/25/6904907.html
-Advertisement-
Play Games

MIME (Multipurpose Internet Mail Extensions) 是描述內容類型的互聯網標準。Clients use this content type or media type header to select an appropriate viewer applicat ...


MIME (Multipurpose Internet Mail Extensions) 是描述內容類型的互聯網標準。Clients use this content type or media type header to select an appropriate viewer application for the type of data the header indicates.  數據接收方根據MIME type of content進行不同的解析。

MIME 消息包含文本(text/…)、圖像(image/…)、音頻(audio/…)、視頻(video/…)以及其他應用程式專用(application/…)的數據。type/subtype

<form> 標簽的 enctype 屬性指定發往伺服器的數據的MIME類型。只有 method="post" 時才使用 enctype 屬性。

取值

描述

application/x-www-form-urlencoded

在發送前會根據HTTP標準編碼所有字元(k=v&k2=v2),空格轉換為 "+" ,特殊符號轉換為 ASCII HEX 值。【在url規範中空格要編碼成%20】

multipart/form-data

不對字元編碼,會增加MIME headers。use when forms contain files, non-ASCII data, and binary data.

text/plain

空格轉換為 "+" 加號,不對特殊字元編碼。

fname欄位的value='chen 1'和name欄位的value='kevin 1'在不同MIME類型下的表現形式:

application/x-www-form-urlencoded 

For application/x-www-form-urlencoded, the body of the HTTP message sent to the server is essentially one giant query string -- name/value pairs are separated by the ampersand (&), and names are separated from values by the equals symbol (=). An example of this would be: 

  MyVariableOne=ValueOne&MyVariableTwo=ValueTwo

According to the specification:

[Reserved and] non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character

That means that for each non-alphanumeric byte that exists in one of our values, it's going to take three bytes to represent it. For large binary files, tripling the payload is going to be highly inefficient.

multipart/form-data

會將多個表單的數據處理為一條消息,數據塊以分隔符=={boundary}開始,以 =={boundary}==結束。會有Content-Type屬性說明文件類型,content-disposition屬性說明欄位的一些具體信息。

  

That's where multipart/form-data comes in. With this method of transmitting name/value pairs, each pair is represented as a "part" in a MIME message (). Parts are separated by a particular string boundary (chosen specifically so that this boundary string does not occur in any of the "value" payloads). Each part has its own set of MIME headers like Content-Type, and particularly Content-Disposition, which can give each part its "name." The value piece of each name/value pair is the payload of each part of the MIME message. The MIME spec gives us more options when representing the value payload -- we can choose a more efficient encoding of binary data to save bandwidth (e.g. base 64 or even raw binary).

Why not use multipart/form-data all the time? For short alphanumeric values (like most web forms), the overhead of adding all of the MIME headers is going to significantly outweigh any savings from more efficient binary encoding.

payload:數據在傳輸過程中會根據各種協議進行封裝,以保證可靠性。去除這些包裹層後真正需要傳輸的數據即payload。 

不同的參數傳遞方式,服務端獲取參數的方式也不同。  

對於提交的application/x-www-form-urlencoded數據(ajax或表單), 在servlet中可以通過request.getParameter(name)的形式來獲取表單參數。

對於multipart/form-data類型的數據,後臺一般需要通過獲取原始數據流做特別處理。

使用原生Ajax Post請求且未指定content-type時,預設使用Content-Type:text/plain;charset=UTF-8頭部,在chrome中請求參數會顯示在Request Payload部分。後臺接受數據後只能當作普通字元使用,不能使用常用API獲取參數。

jQuery.ajax()中預設的content-type為application/x-www-form-urlencoded類型,瀏覽器會將數據編碼成標準的query String,在chrome的Form Data部分可以看到對應的值。適合傳鍵值對數據(’key=value’或{key:value}),不適合對象嵌套對象的數據

application/json

以json格式的字元串形式傳遞參數,在jQuery中需要用JSON.Stringfy()將對象字元串化。如果直接傳對象,最外層的括弧會被去掉,導致解析錯誤。大多數後端語言都支持解析json格式的數據。

  

query string parameters 請求url中的query部分,get和post請求都可以攜帶。

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1.字元串去除左右空格繼承形式// 除去左右空格String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }// 除去左空格String.prototype.LTrim = function() { ...
  • 原文參考http://mp.weixin.qq.com/s?__biz=MzU3MDA0NTMzMA==&mid=2247485510&amp;idx=2&amp;sn=0adff5754a21a46a60ebd5efad48c9f3&source=41#wechat_redirect // 清除控 ...
  • 一、基礎用法 2. 3.枚舉 類的內部所有定義的方法,都是不可枚舉的(non-enumerable)。跟es5中的差距。 4.constructor 方法 constructor方法是類的預設方法,通過new命令生成對象實例時,自動調用該方法。一個類必須有constructor方法,如果沒有顯式定義 ...
  • HTMLcanvas矩形陣雨 在畫布上執行 獲取製圖環境 全屏獲取屏幕寬度和屏幕高度 確定每個文字的寬度 以確定列 迴圈輸出 定時器調用 HTML 部分 CSS 部分 Javascript 部分 此文到此結束 我始終相信這個世界上充滿了美好與希望 加油! ...
  • h5的播放器樣式設置,通過jquery和js原生代碼共同實現 ...
  • js中的5中基本數據類型 js標識符 關鍵字: 保留字: js註釋 js模式 嚴格模式:使用 use strict 混雜模式:不加 use strict js數據類型 js中有5中簡單數據類型,也成為基本數據類型:Undefined, Null, Boolean, Number, String js ...
  • flex在眾多手機瀏覽器上的相容方案(親測華為手機自帶瀏覽器) 如果項目使用構建工具,可加autoprefixer來處理,[autoprefixer使用指南] 純手寫css相容代碼,需給每個使用的屬性加上屬性首碼 /*display: flex;寫法*/ span { display: -webki ...
  • f 指令 語法比較簡單,直接上代碼: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...