How does WP7 upload files and obtain server-side replies? [z]

Source: Internet
Author: User

HttpWebRequest class code:

/// <Summary> /// sent content /// </summary> private byte [] bSendingFile = null; using (IsolatedStorageFileStream sendingZipStream2 = new IsolatedStorageFileStream (strZipFolderName + "/" + strZipFileName, FileMode. open, isoStorage) {try {// file to be uploaded bSendingFile = new byte [sendingZipStream2.Length]; sendingZipStream2.Read (bSendingFile, 0, bSendingFile. length); // create the HttpWebRequest object HttpWebRequest ht Based on the uri TpReq = (HttpWebRequest) WebRequest. create (new Uri (F3StaticResource. sendNMSUrl, UriKind. absolute); httpReq. method = "POST"; httpReq. contentType = "multipart/form-data;"; IAsyncResult asyncResult = httpReq. beginGetRequestStream (new AsyncCallback (RequestStreamCallback), httpReq);} catch (Exception ex) {String strError = ex. toString () ;}/// <summary> /// the returned result is used to write data to Stream, write data, and send /// </summary> // /<Param name = "result"> </param> private void RequestStreamCallback (IAsyncResult result) {HttpWebRequest request = result. asyncState as HttpWebRequest; // returns the Stream requestStream = request that writes data to a URI resource. endGetRequestStream (result); requestStream. write (bSendingFile, 0, bSendingFile. length); requestStream. flush (); requestStream. close (); request. beginGetResponse (new AsyncCallback (ResponseCal Lback), request );} /// <summary> /// obtain the final returned result /// </summary> /// <param name = "result"> </param> private void ResponseCallback (IAsyncResult result) {try {HttpWebRequest request = result. asyncState as HttpWebRequest; WebResponse response = request. endGetResponse (result) as HttpWebResponse; if (response! = Null) {Stream responseStream = response. getResponseStream (); using (StreamReader streamReader = new StreamReader (responseStream) {String strResponese = streamReader. readToEnd (); // returned content} catch (Exception ex) {String strError = ex. toString ();}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.