免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Windows Phone 7下一個(gè)上傳圖片的類_銀光中國 Silverlight 資源 ...


public class RK_URLReqeust { ///summary ///Delegatedeclarationforservercallbacks. ////summary ///paramname=responseTheserverresponse./param public delegate void Callback( string response); ///summary ///Thecallbackfortheserverresponse. ////summary Callbac
  
   public class RK_URLReqeust
    {
        /// <summary>
        /// Delegate declaration for server callbacks.
        /// </summary>
        /// <param name="response">The server response.</param>
        public delegate void Callback(string response);

        /// <summary>
        /// The callback for the server response.
        /// </summary>
        Callback callback;

        /// <summary>
        /// The actual URL.
        /// </summary>
        string url;
        string poststr;

        public Stream Image { getset; }

        /// <summary>
        /// The server response to this URL request.
        /// </summary>
        public string Response { getprivate set; }

        /// <summary>
        /// Constructor.
        /// </summary>
        public RK_URLReqeust(string url, string PostString, Callback callback)
        {
            // Initialize members
            this.url = url;
            this.callback = callback;
            poststr = PostString;
            //State = URLRequestState.Idle;
        }


        /// <summary>
        /// Send the URL request off!
        /// </summary>
        /// <returns>The server response.</returns>
        public void SendPost()
        {
            // Create a background thread to run the web request
            Thread t = new Thread(new ThreadStart(SendPostThreadFunc));
            t.Name = "URLRequest_For_" + url;
            t.IsBackground = true;
            t.Start();
        }

        /// <summary>
        /// The background thread for sending the url request.
        /// </summary>
        void SendPostThreadFunc()
        {
            string boundary = "--------boundary"
            // Create the web request object
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.ContentType = "multipart/form-data; boundary=" + boundary;

            // Start the request
            webRequest.BeginGetRequestStream(new AsyncCallback(GetReqeustStreamCallback), webRequest);

            // Update our state
            //State = URLRequestState.Working;
        }

        /// <summary>
        /// Start the stream request.
        /// </summary>
        /// <param name="asynchronousResult">The asynchronous result object.</param>
        void GetReqeustStreamCallback(IAsyncResult asynchronousResult)
        {
            HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
            string boundary = "--------boundary"
            // End the stream request operation
            Stream postStream = webRequest.EndGetRequestStream(asynchronousResult);

            // 構(gòu)造發(fā)送數(shù)據(jù)
            StringBuilder sb = new StringBuilder();

            // 文件域的數(shù)據(jù)
            sb.Append("--" + boundary);
            sb.Append("\r\n");
            sb.Append("Content-Disposition: form-data; name=\"upload_file\";filename=\"image.jpg\"");
            sb.Append("\r\n");

            sb.Append("Content-Type: ");
            sb.Append("image/jpeg");
            sb.Append("\r\n\r\n");

            string postHeader = sb.ToString();
            byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader); 
            postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);

            // 輸入文件流數(shù)據(jù) 
            byte[] buffer = new Byte[checked((uint)Math.Min(4096, (int)Image.Length))];
            int bytesRead = 0;
            while ((bytesRead = Image.Read(buffer, 0, buffer.Length)) != 0)
                postStream.Write(buffer, 0, bytesRead);


            // 構(gòu)造發(fā)送數(shù)據(jù)
            StringBuilder sb2 = new StringBuilder();
            // 文本域的數(shù)據(jù),將user=eking&pass=123456  格式的文本域拆分 ,然后構(gòu)造 
            foreach (string c in poststr.Split('&'))
            {
                string[] item = c.Split('=');
                if (item.Length != 2)
                {
                    break;
                }
                string name = item[0];
                string value = item[1];
                sb2.Append("--" + boundary);
                sb2.Append("\r\n");
                sb2.Append("Content-Disposition: form-data; name=\"" + name + "\"");
                sb2.Append("\r\n\r\n");
                sb2.Append(value);
                sb2.Append("\r\n");
            }

            byte[] postHeaderBytes2 = Encoding.UTF8.GetBytes("\r\n" + sb2.ToString());

            // Add the post data to the web request
            postStream.Write(postHeaderBytes2, 0, postHeaderBytes2.Length);
            postStream.Close();

            // Start the web request
            webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);
        }

        /// <summary>
        /// Start the URL request.
        /// </summary>
        /// <param name="asynchronousResult">The asynchronous result object.</param>
        void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;

            // End the get response operation
            HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult);
            Stream streamResponse = response.GetResponseStream();
            StreamReader streamReader = new StreamReader(streamResponse);
            Response = streamReader.ReadToEnd();
            streamResponse.Close();
            streamReader.Close();
            response.Close();

            // Call the response callback
            if (callback != null)
            {
                callback(Response);
            }

            // Update state
            //State = URLRequestState.Done;
        }

        public byte[] StreamToBytes(Stream stream)
        {
            byte[] bytes = new byte[stream.Length];
            stream.Read(bytes, 0, bytes.Length);

            // 設(shè)置當(dāng)前流的位置為流的開始   
            stream.Seek(0, SeekOrigin.Begin);
            return bytes;
        }

    }

調(diào)用方式:

            StringBuilder builder = new StringBuilder();
            builder.Append("type=photo&");
            builder.Append("uid=" + JiaYuan._uid + "&");
            builder.Append("token=" + JiaYuan._token);//參數(shù)用&分割  例如 username=****&password=****

RK_URLReqeust rk = new RK_URLReqeust("URL", builder.ToString(), new RK_URLReqeust.Callback(UploadPic_CallBack));

        private void UploadPic_CallBack(string response)
        {
            Dispatcher.BeginInvoke(() =>
            {
                MessageBox.Show(response);
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
HttpWebRequest和HttpWebResponse
jquery動(dòng)態(tài)實(shí)現(xiàn)填充下拉框
Asp.net 導(dǎo)出Excel
Java 下載支持?jǐn)帱c(diǎn)續(xù)傳服務(wù)端
Java 下載支持?jǐn)帱c(diǎn)續(xù)傳
用Java來實(shí)現(xiàn)的Sniffer
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服