• .net 接口返回json格式示例


    1、新建 InterfaceTestPro1 项目:

    FILE - New - Project... - Web - ASP.NET Web Forms Application

    name:InterfaceTestPro1

    2、新建 test.ashx 项:

    项目右键 - Add - New Item.... - Generic Handler

    name:test.ashx

    将 ProcessRequest 方法替换成如下代码

                context.Response.ContentType = "text/plain";
                RspMsg rspMsg = new RspMsg();
                string name = context.Request.Form["name"].ToString();
                rspMsg.ReturnCode = "1";
                rspMsg.ReturnMessage = "Welcome " + name;
                context.Response.Write(rspMsg.ToString());

    3、新建 test.html 项:

    项目右键 - Add - New Item.... - HTML Page

    name:test.html

    代码如下

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <form name="form1" method="post" action="test.ashx">
            name:  <input type="text" name="name" value=""/>
            <input type="submit" value="submit"/>
        </form>
    </body>
    </html>

    4、效果演示:

    提交

    右键查看源码

  • 相关阅读:
    JAVA 异常
    JAVA 接口的基本语法
    JAVA 访问权限
    Linux shell 函数应用示例02
    Linux shell 函数应用示例01
    Linux shell while循环语句
    Linux shell 中断循环语句
    Linux shell for循环结构
    测试用例基本概念
    软件测试原则
  • 原文地址:https://www.cnblogs.com/xw-yanger/p/5139225.html
Copyright © 2020-2023  润新知