zoukankan      html  css  js  c++  java
  • 发送xml或json格式的数据给服务器

    后台通过context.Request.InputStream来接收

    #region 发送消息 + void SendMessage()
    /// <summary>
    /// 发送消息
    /// </summary>
    public void SendMessage()
    {
    //CurrentContext.Response.Write("Hello F1");
    string lbSourceUrl = CurrentContext.Request["lbSourceUrl"];
    string textMessage = CurrentContext.Request["textMessage"];

    byte[] entity = Encoding.UTF8.GetBytes(textMessage);
    HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri(lbSourceUrl));
    httpReq.AllowAutoRedirect = true;
    httpReq.KeepAlive = true;
    httpReq.Method = "POST";
    httpReq.ContentType = "text/xml; charset=UTF-8";  //json格式 application/json;charset=UTF-8
    httpReq.ContentLength = entity.Length;

    Stream reqStream = httpReq.GetRequestStream();
    reqStream.Write(entity, 0, entity.Length);
    reqStream.Close();

    HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse();

    StreamReader respStream = new StreamReader(httpResp.GetResponseStream(), Encoding.UTF8);
    string result = respStream.ReadToEnd();

    respStream.Close();
    httpReq.Abort();
    httpResp.Close();

    CurrentContext.Response.Write(result);
    }
    #endregion

  • 相关阅读:
    java 字符流
    大兴安岭300余幅岩画得到及时保护
    [Hive]-Table
    [Hive]-DataBase
    [Hive]-列式存储篇
    [Hive]-架构篇
    [Hive]编译部署-hive-1.1.0-cdh5.7.0
    [Hadoop]-MapReduce-使用篇
    [Hadoop]MapReduce-架构篇
    [Hadoop]-常用命令
  • 原文地址:https://www.cnblogs.com/james641/p/5015777.html
Copyright © 2011-2022 走看看