如何在内容类型为x

编程入门 行业动态 更新时间:2024-10-23 09:20:53
本文介绍了如何在内容类型为x-www-form-urlencoded的C#中发布请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

邮递员POST请求的图片

我想发出此POST请求以接收OAuth2访问令牌,但在Visual Studio 2015中使用c#代码。

I would like to make this POST request to receive an OAuth2 access token but using c# code in Visual Studio 2015.

谢谢。

推荐答案

System.Net.HttpWebRequest 是您需要知道的类,这很容易样品。有关更多信息,请参见MSDN: https ://msdn.microsoft/zh-CN/library/system.httpwebrequest(v = vs.110).aspx

System.Net.HttpWebRequest is the class you need to know, this is a easy sample. About more infomation see MSDN :msdn.microsoft/en-us/library/system.httpwebrequest(v=vs.110).aspx

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.AllowAutoRedirect = true; webRequest.Timeout = 20 * 1000; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; webRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"; //write the data to post request //Postdata : a=1&b=2&c=3 byte[] buffer = Encoding.Default.GetBytes(Postdata); if (buffer != null) { webRequest.ContentLength = buffer.Length; webRequest.GetRequestStream().Write(buffer, 0, buffer.Length); } WebResponse wr = webRequest.GetResponse()

更多推荐

如何在内容类型为x

本文发布于:2023-10-09 18:24:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476434.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   内容

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!