2012-05-25 35 views
1
void SendPost() 
      { 
       var url = "http://{ipaddress}/Network/Records/Registration?fname=tt&lname=tt&username=dddddddd&password=tt"; 

       HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); 
       myRequest.Method = "POST"; 
       myRequest.ContentType = "application/x-www-form-urlencoded"; 

       myRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), myRequest); 
    } 
void GetRequestStreamCallback(IAsyncResult asynchronousResult) 
     { 
      HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; 
      System.IO.Stream postStream = request.EndGetRequestStream(asynchronousResult); 
      string parametersString = ""; 


      byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(str); 
      // Write to the request stream. 
      postStream.Write(byteArray, 0, byteArray.Length); 
      postStream.Close(); 
      // Start the asynchronous operation to get the response 
      request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request); 
} 



void GetResponseCallback(IAsyncResult asynchronousResult) 
     { 

       HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; 
       HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); 
       Stream streamResponse = response.GetResponseStream(); 
       StreamReader streamRead = new StreamReader(streamResponse); 
       string responseString = streamRead.ReadToEnd(); 
       // Close the stream object 
       streamResponse.Close(); 
       streamRead.Close(); 
       // Release the HttpWebResponse 
       response.Close(); 
} 

我上面寫的代碼發送圖像爲bytes.it沒有給出任何錯誤,但圖像沒有正確上傳。 我在下面的代碼中傳遞base64字符串的圖像。如何將字節圖像發送到windows phone 7中的服務?

byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(str); 

請告訴我什麼是錯。爲什麼圖像沒有正確上傳?

+0

什麼是不工作呢? –

回答

相關問題