Esempio n. 1
0
        //Html必须编码后再传输,html默认的是将其UrlEncode后传递,服务端再编辑,直接传是不能的
        public HttpResult UploadParam(string url, Dictionary <string, object> postParameters)
        {
            HttpMultipartFormRequest req = new HttpMultipartFormRequest();

            req.config = config;
            HttpResult result = new HttpResult();

            result = req.AsyncHttpRequest(url, postParameters, null);
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 以Html形式发送给服务端,服务端以Request.Files[0]接收,文件名TeamFile
        /// </summary>
        /// <param name="argStream">需上传的文件流</param>
        /// <param name="url">目标Url</param>
        /// <param name="fname">上传文件名</param>
        /// <returns>同步模式下会返回信息,异步下用callback</returns>
        public HttpResult UploadFile(string url, Stream argStream, string fname, HttpMultipartFormRequest.ResponseCallback callback = null)
        {
            byte[] bytes = new byte[argStream.Length];
            argStream.Seek(0, SeekOrigin.Begin);
            while (argStream.Read(bytes, 0, bytes.Length) > 0)
            {
                ;                                              //全部读完
            }
            Dictionary <string, object> postParameters = new Dictionary <string, object>();
            string        contentType = "multipart/form-data";//"image/jpeg";//"multipart/form-data";//"application/octetstream";//"image/jpeg";//"multipart/form-data";
            FileParameter param       = new FileParameter(bytes, fname, contentType);

            postParameters.Add(config.fname, param);
            HttpMultipartFormRequest req = new HttpMultipartFormRequest();

            req.config = config;
            HttpResult result = req.AsyncHttpRequest(url, postParameters, callback);

            argStream.Dispose();
            return(result);
        }