zoukankan      html  css  js  c++  java
  • webapi接收post数据

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;
    using System.Web;
    using System.IO;
    namespace swaggerTest1.Controllers
    {
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {
    [HttpGet]
    public string OrderSingle()
    {
    return "测试1";
    }
    [HttpGet]
    public string OrderList()
    {
    return "订单列表";
    }

    [HttpPost]
    public string Upload(UserInfo model)
    {
    //https://localhost:44303/api/Order/Upload
    //{"username":"小五","ZhaiyaoUrl":"23123","QuanwenUrl":"666"}
    string dir = AppDomain.CurrentDomain.BaseDirectory;
    //使用path获取当前应用程序集的执行的上级目录
    dir = Path.GetFullPath("..");
    //使用path获取当前应用程序集的执行目录的上级的上级目录
    dir = Path.GetFullPath("../../../xiaowutemp/");

    if(!Directory.Exists(dir))
    {
    Directory.CreateDirectory(dir);
    }

    string username = model.userName;
    string ZhaiyaoUrl = model.ZhaiyaoUrl;
    string QuanwenUrl = model.ZhaiyaoUrl;
    string quanWenpath = dir + DateTime.Now.ToString("yyyyMMddHHmmss")+"全文.doc" ;
    string zhaiyaoPath = dir + DateTime.Now.ToString("yyyyMMddHHmmss") + "摘要.doc";
    byte[] quanwenByte =Convert.FromBase64String(QuanwenUrl);
    byte[] zhaiyaoByte = Convert.FromBase64String(ZhaiyaoUrl);


    Bytes2File(zhaiyaoByte, zhaiyaoPath);

    Bytes2File(quanwenByte, quanWenpath);
    string res = "success";
    return res;
    }


    /// <summary>
    /// 将byte数组转换为文件并保存到指定地址
    /// </summary>
    /// <param name="buff">byte数组</param>
    /// <param name="savepath">保存地址</param>
    public static void Bytes2File(byte[] buff, string savepath)
    {
    if (System.IO.File.Exists(savepath))
    {
    System.IO.File.Delete(savepath);
    }
    FileStream fs = new FileStream(savepath, FileMode.CreateNew);
    BinaryWriter bw = new BinaryWriter(fs);
    bw.Write(buff, 0, buff.Length);
    bw.Close();
    fs.Close();
    }

    public class UserInfo {

    public string userName { get; set; }

    public string ZhaiyaoUrl { get; set; }

    public string QuanwenUrl { get; set; }
    }
    }
    }

  • 相关阅读:
    考研打卡_Day018
    如何使用python中的pymysql操作mysql数据库
    Linux系统目录结构和常用目录主要存放内容的说明
    MySQL基础入门使用和命令的使用
    Python中property属性的概论和使用方法
    如何有效的优化自己的网站访问速度
    机器学习中的特征工程学习
    ffmpeg中c语言sdk多媒体互转主要使用的api
    FFmpeg使用c语言sdk实现打印视频的信息
    ffmpeg使用C语言sdk实现抽取视频中的视频数据
  • 原文地址:https://www.cnblogs.com/wugh8726254/p/14752732.html
Copyright © 2011-2022 走看看