asp.net webapi测试

2021-03-10 07:29

阅读:665

标签:程序   eric   convert   web   安装   max   size   soft   标准版   

环境vs2010

应用=》管理NuGet程序包,安装MVC 4

技术图片

 

 

新建项目

技术图片

 

 技术图片

 

 ValuesController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Runtime.Serialization.Json;
using Newtonsoft.Json;

namespace TestWebApi.Controllers
{
public class ValuesController : ApiController
{
string ss = " [" +
"{" +
"\"id\": \"4a4c8b8e4d8c22a97a94b46f58c1f3b9\"," +
"\"cover\": \"/images/classify/miphone.png\"," +
"\"title\":" +
"\"1黑莓(BlackBerry)KEY2标准版 6GB+64GB双卡双待 4G全网通手机 黑色 移动联通电信手机\"," +
"\"price\": \"3388.00\"," +
"\"comment\": \"6239\"," +
"\"rate\": \"99%\"" +
"}," +
" {" +
"\"id\": \"5a4c8b8e4d8c22a97a94b46f58c1f3b9\"," +
"\"cover\": \"/images/classify/huawei.png\"," +
"\"title\":" +
"\"2HUAWEI P20 Pro 全面屏徕卡三摄游戏手机 6GB+128GB 亮黑色 全网通移动联通电信4G手机 双卡双待\"," +
"\"price\": \"4499.00\"," +
"\"comment\": \"27万\"," +
"\"rate\": \"99%\"" +
" }," +
"{" +
"\"cover\": \"/images/classify/phone.png\"," +
"\"title\":" +
"\"3荣耀8X Max 7.12英寸90%屏占比珍珠屏 4GB+64GB 魅海蓝 移动联通电信4G全面屏手机 双卡双待\"," +
"\"price\": \"1499.00\"," +
"\"comment\": \"3万\"," +
"\"rate\": \"99%\"," +
"\"id\": \"3a4c8b8e4d8c22a97a94b46f58c1f3b9\"" +
" }," +
" {" +
"\"id\": \"4a4c8b8e4d8c22a97a94b46f58c1f3b9\"," +
"\"cover\": \"/images/classify/miphone.png\"," +
"\"title\":" +
"\"4黑莓(BlackBerry)KEY2标准版 6GB+64GB双卡双待 4G全网通手机 黑色 移动联通电信手机\"," +
"\"price\": \"3388.00\"," +
"\"comment\": \"6239\"," +
"\"rate\": \"99%\"" +
" }," +
"{" +
"\"id\": \"5a4c8b8e4d8c22a97a94b46f58c1f3b9\"," +
"\"cover\": \"/images/classify/huawei.png\"," +
"\"title\":" +
"\"5HUAWEI P20 Pro 全面屏徕卡三摄游戏手机 6GB+128GB 亮黑色 全网通移动联通电信4G手机 双卡双待\"," +
"\"price\": \"4499.00\"," +
"\"comment\": \"27万\"," +
"\"rate\": \"99%\"" +
" }," +
" {" +
"\"cover\": \"/images/classify/phone.png\"," +
"\"title\":" +
"\"6荣耀8X Max 7.12英寸90%屏占比珍珠屏 4GB+64GB 魅海蓝 移动联通电信4G全面屏手机 双卡双待\"," +
"\"price\": \"1499.00\"," +
"\"comment\": \"3万\"," +
"\"rate\": \"99%\"," +
"\"id\": \"3a4c8b8e4d8c22a97a94b46f58c1f3b9\"" +
" }," +
" {" +
"\"id\": \"4a4c8b8e4d8c22a97a94b46f58c1f3b9\"," +
"\"cover\": \"/images/classify/miphone.png\"," +
"\"title\":" +
"\"7黑莓(BlackBerry)KEY2标准版 6GB+64GB双卡双待 4G全网通手机 黑色 移动联通电信手机\"," +
"\"price\": \"3388.00\"," +
"\"comment\": \"6239\"," +
"\"rate\": \"99%\"" +
" }," +
" {" +
"\"id\": \"5a4c8b8e4d8c22a97a94b46f58c1f3b9\"," +
"\"cover\": \"/images/classify/huawei.png\"," +
"\"title\":" +
"\"8HUAWEI P20 Pro 全面屏徕卡三摄游戏手机 6GB+128GB 亮黑色 全网通移动联通电信4G手机 双卡双待\"," +
"\"price\": \"4499.00\"," +
"\"comment\": \"27万\"," +
"\"rate\": \"99%\"" +
" }," +
"{" +
"\"cover\": \"/images/classify/phone.png\"," +
"\"title\":" +
"\"9荣耀8X Max 7.12英寸90%屏占比珍珠屏 4GB+64GB 魅海蓝 移动联通电信4G全面屏手机 双卡双待\"," +
"\"price\": \"1499.00\"," +
"\"comment\": \"3万\"," +
"\"rate\": \"99%\"," +
"\"id\": \"3a4c8b8e4d8c22a97a94b46f58c1f3b9\"" +
" }," +
" {" +
"\"id\": \"4a4c8b8e4d8c22a97a94b46f58c1f3b9\"," +
"\"cover\": \"/images/classify/miphone.png\"," +
"\"title\":" +
"\"10黑莓(BlackBerry)KEY2标准版 6GB+64GB双卡双待 4G全网通手机 黑色 移动联通电信手机\"," +
"\"price\": \"3388.00\"," +
"\"comment\": \"6239\"," +
"\"rate\": \"99%\"" +
" }," +
" {" +
"\"id\": \"5a4c8b8e4d8c22a97a94b46f58c1f3b9\"," +
"\"cover\": \"/images/classify/huawei.png\"," +
"\"title\":" +
"\"11HUAWEI P20 Pro 全面屏徕卡三摄游戏手机 6GB+128GB 亮黑色 全网通移动联通电信4G手机 双卡双待\"," +
"\"price\": \"4499.00\"," +
"\"comment\": \"27万\"," +
"\"rate\": \"99%\"" +
"}," +
" {" +
"\"cover\": \"/images/classify/phone.png\"," +
"\"title\":" +
"\"12荣耀8X Max 7.12英寸90%屏占比珍珠屏 4GB+64GB 魅海蓝 移动联通电信4G全面屏手机 双卡双待\"," +
"\"price\": \"1499.00\"," +
"\"comment\": \"3万\"," +
"\"rate\": \"99%\"," +
"\"id\": \"3a4c8b8e4d8c22a97a94b46f58c1f3b9\"" +
"}," +
"{" +
"\"id\": \"4a4c8b8e4d8c22a97a94b46f58c1f3b9\"," +
"\"cover\": \"/images/classify/miphone.png\"," +
"\"title\":" +
"\"13黑莓(BlackBerry)KEY2标准版 6GB+64GB双卡双待 4G全网通手机 黑色 移动联通电信手机\"," +
"\"price\": \"3388.00\"," +
"\"comment\": \"6239\"," +
"\"rate\": \"99%\"" +
" }," +
"{" +
"\"id\": \"5a4c8b8e4d8c22a97a94b46f58c1f3b9\"," +
"\"cover\": \"/images/classify/huawei.png\"," +
"\"title\":" +
"\"14HUAWEI P20 Pro 全面屏徕卡三摄游戏手机 6GB+128GB 亮黑色 全网通移动联通电信4G手机 双卡双待\"," +
"\"price\": \"4499.00\"," +
"\"comment\": \"27万\"," +
"\"rate\": \"99%\"" +
" }," +
" {" +
"\"cover\": \"/images/classify/phone.png\"," +
"\"title\":" +
"\"15荣耀8X Max 7.12英寸90%屏占比珍珠屏 4GB+64GB 魅海蓝 移动联通电信4G全面屏手机 双卡双待\"," +
"\"price\": \"1499.00\"," +
"\"comment\": \"3万\"," +
"\"rate\": \"99%\"," +
"\"id\": \"3a4c8b8e4d8c22a97a94b46f58c1f3b9\"" +
"}" +
" ]";
// GET api/values
public List GetVlues()
{

List prolist = JsonConvert.DeserializeObject>(ss);
return prolist;
}

// GET api/values/5
public List GetPage(int page, int size)
{
List prolist = JsonConvert.DeserializeObject>(ss);
List ret = new List();
int start=(page-1)*size;
for (int i = start; i {
if (i {
if (prolist[i] != null)
{
ret.Add(prolist[i]);
}
}
}
return ret;
}

// POST api/values
public void Post([FromBody]string value)
{
}

// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}

// DELETE api/values/5
public void Delete(int id)
{
}
}
public class product
{
public string id;
public string cover;
public string title;
public float price;
public string comment;
public string rate;
}

//"id\": \"4a4c8b8e4d8c22a97a94b46f58c1f3b9",
//"cover\": \"/imagess/classify/miphone.png",
//"title":
// "黑莓(BlackBerry)KEY2标准版 6GB+64GB双卡双待 4G全网通手机 黑色 移动联通电信手机",
//"price\": \"3388.00",
//"comment\": \"6239",
//"rate\": \"99%"
}

 

发布,配置网站,测试

技术图片

 

asp.net webapi测试

标签:程序   eric   convert   web   安装   max   size   soft   标准版   

原文地址:https://www.cnblogs.com/playforever/p/12705392.html


评论


亲,登录后才可以留言!