2014-05-20 61 views
0

IM使在WPF應用程序,它使用RESTful API,因此從sharefile IM使得autorisation 到目前爲止,我有這個HttpWebRequest的WPF中

private void Button_Click_1(object sender, RoutedEventArgs e) 
    { 
     Uri uri = new Uri("https://secure.sharefile.com/oauth/authorize"); 
     HttpWebRequest request = WebRequest.CreateHttp(uri); 
     shareFileWebView.Navigate(uri); 
     request.Method = "POST"; 
     shareFileWebView. // but i supose to get something from here 
     HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
     Console.WriteLine(response.StatusCode); 
     JObject token = null; 
     using (var reader = new StreamReader(response.GetResponseStream())) 
     { 
      string body = reader.ReadToEnd(); 
      token = JObject.Parse(body); 
     } 

     OAuth2Token _tokene =new OAuth2Token(token); 

    } 

我需要獲得令牌,但如何從獲得網頁瀏覽器?在webr瀏覽器中,用戶填寫他的賬戶數據,任何想法?

+0

你有沒有得到這個地方?你如何獲得你上傳文件的鏈接? –

回答

0

Http請求(例如發送圖像):

public string httpRequest(string url,byte[] image) 
     { 
      try 
      { 
       var request = (HttpWebRequest)WebRequest.Create(url); 
       request.Method = "Post"; 
       request.ContentType = "multipart/form-data"; 
       request.ContentLength = image.Length; 
       using (Stream postStream = request.GetRequestStream()) 
       { 
        postStream.Write(image, 0, image.Length); 
        postStream.Close(); 
        WebResponse response = request.GetResponse(); 
        var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); 
        if (!string.IsNullOrEmpty(responseString)) 
         return responseString; 
        return null; 
       } 
      } 
      catch (Exception ex) 
      { 
       return ex.Message; 
      } 
     } 

或:

public string RunCommand() 
     { 
      ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; 

      var request = (HttpWebRequest)WebRequest.Create("url"); 
      var response = (HttpWebResponse)request.GetResponse(); 
      var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); 
      response.Close(); 

      return responseString; 
     }