为什么发布base64编码的图像是空的?

时间:2011-11-30 06:43:45

标签: c#

我想使用POST方法并使用以下代码将base64编码的图像发送到远程服务器。 但是长度为零的远程服务器中的内容为空。 这有什么问题?我对base64的编码是错误的吗?

        string Base64;
         byte[] by;
         by=File.ReadAllBytes(Server.MapPath("Sunset.jpg"));
         Base64 = Convert.ToBase64String(by);
         Server.UrlEncode(Base64);
         Automation.Sending(Base64);

Automation Class:
    sending method:
    public static void sending(string Base)
        {
            String s;
            string pass ="xx";
            StringBuilder postData = new StringBuilder(1000);
            postData = new StringBuilder(100);
            postData.Append("module=Scan&action=addPict");
            postData.Append("&user=xxx");
            postData.Append("&pass=" + pass);
            postData.Append("&Id=");
            postData.Append("660913");
            postData.Append("&content =" + Base);// Base64 encoded file
            s = doRequest(postData);

        }
    DoRequest method:
     private static String doRequest(StringBuilder postData)
        {
            byte[] dataArray = Encoding.UTF8.GetBytes(postData.ToString());

            HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create("http://10.10.2.97/officeas/Runtime/process.php?");
            httpRequest.Method = "POST";
            httpRequest.ContentType = "application/x-www-form-urlencoded";

            httpRequest.ContentLength = dataArray.Length;
            Stream requestStream = httpRequest.GetRequestStream();
            requestStream.Write(dataArray, 0, dataArray.Length);
            requestStream.Flush();
            requestStream.Close();

            HttpWebResponse webResponse = (HttpWebResponse)httpRequest.GetResponse();

            if (httpRequest.HaveResponse == true)
            {
                Stream responseStream = webResponse.GetResponseStream();
                StreamReader responseReader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
                String responseString = responseReader.ReadToEnd();
                return responseString;
            }
            else
                Console.Write("no response");

            return "";

        }

0 个答案:

没有答案