2013-06-18 115 views
0

我一直在試圖發送數據到一個web API VIA帖子。但它似乎並沒有發送它。發佈數據到網絡API

下面是我如何做到這一點。

var baseAddress = "http://192.168.0.103/vchatapi/api/Images?gsmNumber=" + profileNumberLbl.Content + "&content=" + base64 + "&contentType=image/" + contentType; 
var http = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(new System.Uri(baseAddress)); 
    http.Accept = "application/json"; 
    http.ContentType = "application/json"; 
    http.Method = "POST"; 

該代碼可以使用GET:

var baseAddress = "http://192.168.0.103/vchatapi/api/SendSMSVerificationCode?gsmNumber=" + areCode + mobile + "&udid=123456"; 
var http = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(new System.Uri(baseAddress)); 
http.Accept = "application/json"; 
http.ContentType = "application/json"; 
http.Method = "GET"; 

try 
        { 
         var response = http.GetResponse(); 

         var stream = response.GetResponseStream(); 
         var sr = new StreamReader(stream); 
         var content = sr.ReadToEnd(); 

         verificationCode = verificationCode.FromJson(content); 
         if (!verificationCode.Equals("")) 
         { 
          MessageBox.Show(this, "Verification Code: " + verificationCode); 
          verificationTextBox.IsEnabled = true; 
          areaCodeCB.IsEnabled = false; 
          mobileNumberTB.IsEnabled = false; 
         } 
         else 
         { 
          MessageBox.Show(this, "Invalid Number"); 
         } 
        } 
        catch (Exception ex) 
        { 
         MessageBox.Show(this, ex.Message); 
        } 

任何想法?謝謝!

回答