【生意多】-免费发布分类信息
当前位置: 首页 » 新闻 » 教程 » 操作系统 » 正文

列类型=文本(论述类文本类型)

放大字体  缩小字体 发布日期:2022-06-30 18:03:25    浏览次数:10

MediaType,即是Internet Media Type,互联网媒体类型;也叫做MIME类型,在Http协议消息头中,使用Content-Type来表示具体请求中的媒体类型信息。

类型格式:type/subtype(;parameter)? type
主类型,任意的字符串,如text,如果是号代表所有; 
subtype 子类型,任意的字符串,如html,如果是
号代表所有; 
parameter 可选,一些参数,如Accept请求头的q参数, Content-Type的 charset参数。 
例如: Content-Type: text/html;charset:utf-8;
常见的媒体格式类型如下:

 text/html : HTML格式text/plain :纯文本格式     text/xml :  XML格式image/gif :gif图片格式   image/jpeg :jpg图片格式image/png:png图片格式application/xhtml+xml :XHTML格式application/xml     : XML数据格式application/atom+xml  :Atom XML聚合格式   application/json    : JSON数据格式application/pdf       :pdf格式 application/msword  : Word文档格式application/octet-stream : 二进制流数据(如常见的文件下载)application/x-www-form-urlencoded : <form encType=””>中默认的encType,form表单数据被编码为key/value格式发送到服务器(表单默认的提交数据的格式)multipart/form-data : 需要在表单中进行文件上传时,就需要使用该格式

示例代码:

using System;using System.Collections;using System.Collections.Generic;using UnityEngine;/// <summary>/// Get和Post最直观的区别就是GET把参数包含在URL中,POST通过request body传递参数。/// </summary>public class HttpTest : MonoBehaviour {    /// <summary>    /// get方法    /// </summary>    /// <returns></returns>    IEnumerator Get()    {        string fullUrl = @"http://xxxxxx?id=0";//id为参数        using (WWW www = new WWW(fullUrl))        {            yield return www;            if (www.error != null)            {                Debug.LogError("error:" + www.error);            }            Debug.Log(www.text);        }    }    /// <summary>    /// application/json连接类型    /// </summary>    /// <returns></returns>    IEnumerator PostJson()    {        string fullUrl = @"http://xxxxxxxx";        //加入http 头信息        Dictionary<string, string> JsonDic = new Dictionary<string, string>();        JsonDic.Add("Content-Type", "application/json");        //body        SendData sendData = new SendData();        sendData.app_key = "1bf5376b82f88384ebe2297327ae2f9fe547dfed";        sendData.time_stamp= "1551174536";        sendData.nonce_str= "123456789";        sendData.sign= "1bf5376b82f88384ebe2297327ae2f9fe547dfed";        sendData.img_type= "URL";        byte[] data = System.Text.Encoding.Default.GetBytes(JsonUtility.ToJson(sendData));        using (WWW www = new WWW(fullUrl, data, JsonDic))        {            yield return www;            if (www.error != null)            {                Debug.LogError("error:" + www.error);            }            Debug.Log(www.text);        }    }    /// <summary>    /// application/x-www-form-urlencoded连接类型    /// </summary>    /// <returns></returns>    IEnumerator PostForm()    {        string fullUrl = @"http://xxxxxxxx";        //加入http 头信息        Dictionary<string, string> JsonDic = new Dictionary<string, string>();        JsonDic.Add("Content-Type", "application/x-www-form-urlencoded");        JsonDic.Add("cache-control", "no-cache");        JsonDic.Add("Postman-Token", "901451c5-e8c6-4322-8e63-754170323404");        //body        WWWForm form = new WWWForm();        form.AddField("app_key", "1bf5376b82f88384ebe2297327ae2f9fe547dfed");        form.AddField("time_stamp", "1551174536");        form.AddField("nonce_str", "123456789");        form.AddField("sign", "1bf5376b82f88384ebe2297327ae2f9fe547dfed");        form.AddField("img_type", "URL");        using (WWW www = new WWW(fullUrl, form.data, JsonDic))        {            yield return www;            if (www.error != null)            {                Debug.LogError("error:" + www.error);            }            Debug.Log(www.text);        }    }}//定义的数据结构[Serializable]public class SendData{    public string app_key;    public string time_stamp;    public string nonce_str;    public string sign;    public string img_type;}
 
(文/小编)
打赏
免责声明
• 
本文为小编原创作品,作者: 小编。欢迎转载,转载请注明原文出处:https://www.31duo.com/news/show-3574090.html 。本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们。
 

(c)2016-2019 31DUO.COM All Rights Reserved浙ICP备19001410号-4

浙ICP备19001410号-4