Esempio n. 1
0
    /// <summary>
    /// 发起post请求,并将请求结果存储在制定的文件内
    /// </summary>
    /// <param name="url"></param>
    /// <param name="jsonData"></param>
    /// <param name="fileName"></param>
    /// <returns>成功</returns>
    public static ZmJieGuo post2Save(string url, string jsonData, string filepath)
    {
        ZmJieGuo jg = new ZmJieGuo();

        try
        {
            //请求
            var myWebRequest = WebRequest.Create(url);
            myWebRequest.Method      = "POST";
            myWebRequest.ContentType = "application/json";
            byte[] data = Encoding.UTF8.GetBytes(jsonData);
            myWebRequest.ContentLength = data.Length;
            Stream newStream = myWebRequest.GetRequestStream();
            newStream.Write(data, 0, data.Length);
            newStream.Close();
            //接收
            var myWebResponse = myWebRequest.GetResponse();
            var ReceiveStream = myWebResponse.GetResponseStream();
            if (ReceiveStream != null)
            {
                //创建本地文件写入流
                Stream stream = new FileStream(filepath, FileMode.Create);
                byte[] bArr   = new byte[1024];
                int    size   = ReceiveStream.Read(bArr, 0, (int)bArr.Length);
                while (size > 0)
                {
                    stream.Write(bArr, 0, size);
                    size = ReceiveStream.Read(bArr, 0, (int)bArr.Length);
                }
                stream.Close();
            }
            myWebResponse.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine("post2Save异常。。。“+" + ex.Message + "+”。。\r\n");
            return(jg.Error(ex.Message));
        }
        return(jg);
    }
Esempio n. 2
0
        private ZmJieGuo AddShengYin(string txt, string uid, string fenlei)
        {
            AliTtsOption ao = new AliTtsOption();

            ao.text = txt;
            ZmJieGuo jg = AliTTSHelper.txt2ShengYin(ao);

            if (jg.isOk)
            {
                ZmParameterList parameters = new ZmParameterList();
                parameters.AddParam("uid", uid);
                parameters.AddParam("sid", jg.data.ToString());
                parameters.AddParam("txt", ao.text);
                parameters.AddParam("fenlei", fenlei);
                int i_jg = MySqlHelper.InsertTab("fanyijilu", parameters.ParamList);
                if (i_jg != 1)
                {
                    return(jg.Error("翻译成功,插入数据库失败"));
                }
            }
            return(jg);
        }