zoukankan      html  css  js  c++  java
  • C# 模拟from表单提交webservice

    public static string test( string user_id, string eventId, string page, string pageSize, string message)//接口需要的参数自定义
    {
    string postUrl = "http:";//接口连接
    string ret = string.Empty;//返回字符串
    try
    {
    NameValueCollection na = new NameValueCollection();//添加参数
    na.Add("user_id", user_id);
    na.Add("eventId", eventId);
    na.Add("pageOffset", page);
    na.Add("pageSize", pageSize);

    byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(na.ToString());//编码格式
    //HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
    System.Net.WebClient WebClientObj = new System.Net.WebClient();
    byte[] bytes = WebClientObj.UploadValues(postUrl, "POST", na);//提交方式POST
    string st = System.Text.Encoding.UTF8.GetString(bytes);得到返回的json
    ret = st;
    }
    catch (Exception ex)
    {
    }
    return ret;
    }

  • 相关阅读:
    OSX中zsh新增环境变量
    新的开始 春光明媚
    tmux
    继承
    6
    Object类
    网页收藏
    画王八
    ES6 语法之import export
    ES6 语法 之 destructuring
  • 原文地址:https://www.cnblogs.com/li-lun/p/4698788.html
Copyright © 2011-2022 走看看