zoukankan      html  css  js  c++  java
  • C#请求接口

    上代码,方便查看【摘抄】

    System.Net.WebClient WebClientObj = new System.Net.WebClient();
    System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
    PostVars.Add("userid", userid);
    
    
    byte[] byRemoteInfo = null;
    string url = "http://~";
    byRemoteInfo = WebClientObj.UploadValues(url, "POST", PostVars);
    string str = System.Text.Encoding.UTF8.GetString(byRemoteInfo);

     使用案例:

    protected void ebtSync_Click(object sender, EventArgs e)
    {
        DataTable dtChoose = GridShow1.ChooseTable;
        System.Net.WebClient WebClientObj = new System.Net.WebClient();
        System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
        PostVars.Add("usercode", "aa");
        PostVars.Add("module", "bb");
        byte[] byRemoteInfo = null;
        string url = "http://localhost:8080/DaiBan.ashx";
        byRemoteInfo = WebClientObj.UploadValues(url, "POST", PostVars);
        string str = System.Text.Encoding.UTF8.GetString(byRemoteInfo);
        testEntity result = new JavaScriptSerializer().Deserialize<testEntity>(str);
        if (str == "success")
        {
            this.Message("同步成功!");
        }
        else {
            this.Message("同步失败!");
        }
    }
    作者:chenze
    出处:https://www.cnblogs.com/chenze-Index/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    如果文中有什么错误,欢迎指出。以免更多的人被误导。
  • 相关阅读:
    springcloud的配置
    springboot面试题
    SqlServer取值四舍五入
    java导出Excel表格简单的方法
    pandas处理数据textrank提取关键词
    toarray()时出现memory error问题解决
    回溯法解决N皇后问题 C语言
    图论中四个最短路径算法
    第一个java程序
    js 实现简单屏蔽某个地区的访问
  • 原文地址:https://www.cnblogs.com/chenze-Index/p/11756882.html
Copyright © 2011-2022 走看看