zoukankan      html  css  js  c++  java
  • 在后端C#中 call web api 关联lookup 和 GUID

    在上个blog中,我们介绍了 在C# 中的怎么用web api来做CURD.  在后端C#中 call web api 

     今天来介绍怎么再web api中写入lookup 和 guid

     guid 相对来说比较简单, 只是一个string,

    Lookup 则需要先关联一下

                    var weburi = resourceUrl + "api/data/v9.1/accounts";
                    AuthenticationContext authContext = new AuthenticationContext("https://login.windows.net/common", false);
                    AuthenticationResult result = authContext.AcquireToken(resourceUrl, clientId, new UserCredential(account, password));
                    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(weburi);
    
                    req.Method = "post";
                    req.Accept = "application/json";
                    req.ContentType = "application/json; charset=utf-8";
                    req.Headers.Add("OData-MaxVersion", "4.0");
                    req.Headers.Add("OData-Version", "4.0");
                    req.Headers.Add("If-Match","*");
                    req.Headers.Set("Authorization", "Bearer " + result.AccessToken);
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    
                    var newSurveyResult = new JObject();
                    newSurveyResult.Add("booleanvalue", true);
                    newSurveyResult.Add("stringvalue", "Hello World!");
                    var interviewee = "/sfdhl_0365users(fa903a51-3d2a-48d5-bbbb-c225f1cf2482)";
                    newSurveyResult.Add("o365userinterviewee@odata.bind", interviewee);
                    newSurveyResult.Add("businessgroup", "fa903a51-3d2a-48d5-bbbb-c225f1cf2482");
                    byte[] data = Encoding.UTF8.GetBytes(newSurveyResult.ToString());
                    Stream newStream = req.GetRequestStream();
                    newStream.Write(data, 0, data.Length);
                    newStream.Close();
                    using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
                    {
                        //StreamReader read = new StreamReader(res.GetResponseStream());
                        string head = res.Headers.ToString();
                    }    
  • 相关阅读:
    Dart语言--基础内容
    Vuex入门介绍
    videojs中文文档详解
    在Vue中如何使用axios请求拦截
    vue监听滚动事件,实现滚动监听(scroll滚动)
    font-family:中文字体的英文名称 (宋体 微软雅黑)
    VUE项目中按需引入ECharts.js
    VUE 重载组件
    【Web】网站主如何更改网页标签的图标(favicon.ico)
    我的电脑cmd命令引入sql数据库
  • 原文地址:https://www.cnblogs.com/TheMiao/p/12500947.html
Copyright © 2011-2022 走看看