zoukankan      html  css  js  c++  java
  • C#模拟HTTP请求Post JSON

      前言

      因为接口是http的,我们站点是https的,不能https直接ajax请求http,所以需要在SharePoint中开发一个模拟请求Ajax的Service,分享一下。

    var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://url");
    httpWebRequest.ContentType = "application/json";
    httpWebRequest.Method = "POST";
    
    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
    {
        string json = "{"user":"test"," +
                      ""password":"bla"}";
    
        streamWriter.Write(json);
        streamWriter.Flush();
        streamWriter.Close();
    }
    
    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
    {
        var result = streamReader.ReadToEnd();
    }
  • 相关阅读:
    bzoj1914
    bzoj3144
    bzoj2756
    poj3177
    一些比较水的题目
    bzoj2282
    屯题50AC纪念
    Base64解码中文部分中文乱码的原因
    随机生成36位字符串
    jQuery判断某个元素是否存在某个样式
  • 原文地址:https://www.cnblogs.com/jianyus/p/10101867.html
Copyright © 2011-2022 走看看