首页 > 其他分享 >webapi body 参数获取数据

webapi body 参数获取数据

时间:2023-10-17 11:36:19浏览次数:40  
标签:webapi body JsonString string Encoding buffer request 获取数据 dt

public string HttpPost()
        {
            string strURL = "";
            DataTable dt = new Arichive().GetKEY();
            string JsonString = string.Empty;
            JsonString = "{\"appKey\":\"" + dt.Rows[0]["APPKEY"] + "\",\"appSecret\":\"" + dt.Rows[0]["APPSECRET"] + "\"}";
            // JsonString = JsonConvert.SerializeObject(dt);//转成json
            strURL = url + "/api/token";
            Encoding encoding = Encoding.UTF8;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
            request.Method = "POST";
            request.Accept = "text/html, application/xhtml+xml, */*";
            request.ContentType = "application/json";
            
                byte[] buffer = encoding.GetBytes(JsonString);
                request.ContentLength = buffer.Length;
                request.GetRequestStream().Write(buffer, 0, buffer.Length);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    return reader.ReadToEnd();
                }
           
        }

 

标签:webapi,body,JsonString,string,Encoding,buffer,request,获取数据,dt
From: https://www.cnblogs.com/lyq666666/p/17769276.html

相关文章

  • WebAPI和MVC的区别
    1.MVC主要用于建站,WebAPI主要用于构建http服务MVC是前端和后端不分离,WebApi是后端写的http服务提供前端,是前后端分离的写法;2.MVC可以返回JsonResult,前端可以直接使用;WebAPI要返回JSON数据,必须JSON.parse()转化为(Maticsoft.Json.dll)3. MVC直接继承system.mvc.cont......
  • webapi跨域访问
    1、在webconfig配置文件里面加入<system.webServer><customHeaders><addname="Access-Control-Allow-Origin"value="*"/><addname="Access-Control-Allow-Headers"value="authorization,Authoriz......
  • 【精品】使用druid 获取数据库表的信息
    Maven依赖<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifac......
  • C# Webapi 简单的依赖注入-构造函数
    控制器部分:usingMicrosoft.AspNetCore.Mvc;usingWebApplication1.IServices;usingWebApplication1.Utility.SwaggerExt;namespaceWebApplication1.Controllers{[ApiController][Route("[controller]")]//指定当前的控制器是哪个Swagger版本的指定给......
  • C# webapi 跨域
    #region启用跨域访问app.UseCors(builder=>builder.AllowAnyMethod().SetIsOriginAllowed(_=>true).AllowAnyHeader().AllowCredentials());#endregionapp.UseCors(); //允许来自任何来源、使用任何HTTP方法、包含任何HTTP头的跨域请求,......
  • webapi action 参数
    使用地址参数传递(queryString)数据:eg:http://localhost:5063/WeatherForecast?age=123///<summary>///GET方法///</summary>///<returns></returns>[HttpGet(Name="GetWea阿斯顿rFoasasst")]publi......
  • 简单 webapi 登录成功就返回 电脑的进程信息·
    ///<summary>///如果登录成功就返回电脑的进程信息///</summary>///<returns></returns>[HttpPost]publicLoginResponseLogin(LoginRequestreq){if(req.UserName=="admin"&......
  • req.body为undefined
    查看package.json中是下载过body-parser如果没有则通过npm下载body-parservarbodyParser=require('body-parser');varapp=express();app.use(bodyParser.json());app.use(bodyParser.urlencoded({extended:false}));//以下为路由配置varroutes=require('./r......
  • WebApi接口
     https://blog.csdn.net/weixin_43430200/article/details/126785026?ops_request_misc=&request_id=&biz_id=102&utm_term=c&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-5-126785026.142^v94^insert_down28v1&sp......
  • SqlServer中获取数据库中每个表的行数
    SqlServer中获取数据库中每个表的行数CREATETABLE#RowCounts(NumberOfRowsBIGINT,TableNameVARCHAR(128))EXECsp_MSForEachTable'INSERTINTO#RowCountsSELECTCOUNT_BIG(*)ASNumberOfRows,''?''asTableNameFROM?'SELECTTableName,Num......