2013-06-18 74 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); 
        } 

任何想法?谢谢!

回答