码迷,mamicode.com
首页 > Web开发 > 详细

上传图片到第三方服务器

时间:2018-10-31 18:29:37      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:keep   col   结果   false   ret   response   path   app   sum   

代码

/// <summary>
    /// 上传图片到第三方服务器
    /// </summary>
    /// <param name="filePath"></param>
    /// <param name="picNo"></param>
    /// <returns></returns>
    public string UploadFilesToBlueBox(string filePath, string picNo)
    {
        string strReturn = "";
        string fileName = Path.GetFileName(filePath);
        string strPostUrl = "http://pic.xxx.com/HttpPost_Upload.aspx?PICID=" + picNo + "&FILENAME=" + fileName;
        HttpWebRequest reqPost = (HttpWebRequest)WebRequest.Create(strPostUrl);
        reqPost.Method = "POST";
        reqPost.KeepAlive = false;
        reqPost.ContentType = "application/x-www-form-urlencoded";

        byte[] fileStream = AuthGetFileData(filePath);//把文件转为bute[],看之前的博客
        string strStream = Convert.ToBase64String(fileStream);
        byte[] strFiledata = Encoding.UTF8.GetBytes(strStream);
        reqPost.ContentLength = strFiledata.Length;
        //post数据
        using (Stream newStream = reqPost.GetRequestStream())
        {
            newStream.Write(strFiledata, 0, strFiledata.Length);
            //获取返回
            HttpWebResponse myResponse = (HttpWebResponse)reqPost.GetResponse();
            using (StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8))
            {
                //返回结果
                strReturn = reader.ReadToEnd();
            }
        }
        return strReturn;
    }

 

上传图片到第三方服务器

标签:keep   col   结果   false   ret   response   path   app   sum   

原文地址:https://www.cnblogs.com/xsj1989/p/9884752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!