• 接口post +json +bean


    public ReturnBean<DealBean> getMember(String tagtype, String tag)
    {

    try
    {
    String requestUrl = getObjectUrl(SynUrl.getMemberByCondition, new String[] { "vendorId", "posCode", "tagtype", "tag", }, new Object[] { posset.VendorId, posset.PosCode, tagtype,tag}, posset.VendorId);
    String result = HttpWebHelper.OpenReadWithHttps(requestUrl.ToString(), null);
    ReturnBean<DealBean> rb = (ReturnBean<DealBean>)Newtonsoft.Json.JsonConvert.DeserializeObject(result, typeof(ReturnBean<DealBean>));
    return rb;
    }
    catch (Exception exx)
    {
    return null;
    }
    }

    private String getObjectUrl(String bizUrl, String[] parameterNames, Object[] parameterValue, long vendorId, String serverUrl = null)
    {
    if (string.IsNullOrEmpty(serverUrl))
    {
    Posset posset = SystemConfig.getPosset();
    serverUrl = posset.ServerUrl;//先取数据库中的设置
    }
    if (string.IsNullOrEmpty(serverUrl)) {//如果为空再去默认的设置
    serverUrl = SynUrl.ServersUrl;
    }
    if (!serverUrl.EndsWith("/"))//是否以/结尾
    {
    serverUrl = serverUrl + bizUrl;
    }
    else {
    serverUrl = serverUrl.TrimEnd('/') + bizUrl;
    }
    if (!serverUrl.Contains("?"))//是否以?结尾
    {
    serverUrl = serverUrl + "?";
    }
    StringBuilder sb = new StringBuilder();
    sb.Append(serverUrl);
    if (parameterNames != null) {
    for (int i = 0; i < parameterNames.Length; i++) {
    if (serverUrl.EndsWith("?") && i == 0)//只有以?结束并且i=0的时候&符号才可以不要
    {
    sb.AppendFormat(parameterNames[i] + "={0}", parameterValue[i]);
    }
    else{
    sb.AppendFormat("&"+parameterNames[i] + "={0}", parameterValue[i]);
    }

    }
    }
    string resultStr=sb.ToString();
    string queryString = resultStr.Substring(resultStr.IndexOf("?")+1, resultStr.Length-resultStr.IndexOf("?")-1);
    Regex oRegex = new Regex(@"[u4E00-u9FA5]");
    string dealQueryString =oRegex.Replace(queryString, "");//要处理下汉字 因为两边的加密不一样
    string vendorstr = Encrypt.Encrypt_MD5(Encrypt.Encrypt_MD5(vendorId+"").ToUpper()).ToUpper();
    //----处理签名
    string sign = Encrypt.Encrypt_MD5(dealQueryString + vendorstr).ToUpper();
    sb.Append("&sign=" + sign);//把签名补上
    return sb.ToString();
    }

    public static string OpenReadWithHttps(string URL, IDictionary<string, string> parameters, int timeout = 60000, string method = "POST", string strEncoding = "utf-8")
    {
    Encoding encoding = Encoding.UTF8;
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
    string strPostdata = null;
    if (parameters != null && parameters.Count > 0)
    {
    strPostdata = "";
    string press = "";
    foreach (KeyValuePair<string, string> kv in parameters)
    {
    strPostdata += press + kv.Key + "=" + kv.Value;
    press = "&";
    }
    }
    request.Method = method;
    request.Accept = "text/html, application/xhtml+xml, */*";
    request.ContentType = "application/x-www-form-urlencoded";
    if (!string.IsNullOrEmpty(strPostdata))
    {
    byte[] buffer = encoding.GetBytes(strPostdata);
    request.ContentLength = buffer.Length;
    request.GetRequestStream().Write(buffer, 0, buffer.Length);
    }
    request.Timeout = timeout;
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(strEncoding)))
    {
    return reader.ReadToEnd();
    }

    }



    public static FlightsResponse QueryFlightPost(FlightQueryRequest ReqDTO) { FlightsResponse FlightsRespDTO = new FlightsResponse(); try { string requestDTO = JsonConvert.SerializeObject(ReqDTO); MediaTypeFormatter jsonFormatter = new JsonMediaTypeFormatter(); HttpContent httpContent = new ObjectContent(ReqDTO, jsonFormatter); var url = RequestUrl + "/QueryFlight"; var httpClient = new HttpClient(new RequestHandler() { InnerHandler = new HttpClientHandler() }); httpClient.Timeout = TimeSpan.FromMinutes(3); var responseJson = httpClient.PostAsync(url, httpContent).Result; FlightsRespDTO = responseJson.Content.ReadAsAsync().Result; } catch (Exception) { FlightsRespDTO = new FlightsResponse(); } return FlightsRespDTO; }
    至少证明我们还活着
  • 相关阅读:
    traceroute tracert 路由器地址 清单 192.168.2.1 网关路由器地址
    /usr/local/nginx/sbin/nginx -s reload 失败原因pid 进程记录和当前不符
    Nginx应用-Location路由反向代理及重写策略 请求转发-URL匹配规则 NGINX Reverse Proxy
    (转载)你好,C++(1)C++是什么?C++的“前世今生”
    (原创)cocos2d-x 3.0 示例代码分析5:testBasic
    (原创)cocos2d-x 3.0 示例代码分析4:VisibleRect
    (原创)cocos2d-x 3.0 示例代码分析3:BaseTest
    (摘要)100个伟大的商业理念:理念35:引爆流行
    (摘要)100个伟大的商业理念:理念34:企业社会责任
    (摘要)100个伟大的商业理念:理念32:重新改造
  • 原文地址:https://www.cnblogs.com/pengde/p/4649220.html
Copyright © 2020-2023  润新知