HttpWebRequest in wpf
本文关键字:wpf in HttpWebRequest | 更新日期: 2023-09-27 18:04:29
我在wpf中制作一个应用程序,它使用restful api,从sharefile中进行授权到目前为止,我有这个
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);
}
我需要得到那个令牌,但我怎么能从浏览器得到?在web浏览器中,用户填写他的帐户数据,有什么想法吗??
这个链接给你你需要的吗?http://api.sharefile.com/rest/api-key.aspx
带正文的Http请求(例如send image):
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;
}