Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从以下给定的POST数据发出HttpWebRequest_C#_Twitter_System.net.httpwebrequest - Fatal编程技术网

C# 从以下给定的POST数据发出HttpWebRequest

C# 从以下给定的POST数据发出HttpWebRequest,c#,twitter,system.net.httpwebrequest,C#,Twitter,System.net.httpwebrequest,说到网络开发,我知道的很少 我在下面的网站上找到了一些代码和解释 最后,我想用twitter实现登录。但我很难将这些POST web请求重写为c#HttpWebRequest格式,以便在其他应用程序中重用。如果我们检查发出的第一个webrequest POST /oauth/request_token HTTP/1.1 User-Agent: themattharris' HTTP Client Host: api.twitter.com Accept: */* Authorizatio

说到网络开发,我知道的很少

我在下面的网站上找到了一些代码和解释

最后,我想用twitter实现登录。但我很难将这些POST web请求重写为c#HttpWebRequest格式,以便在其他应用程序中重用。如果我们检查发出的第一个webrequest

POST /oauth/request_token HTTP/1.1
 User-Agent: themattharris' HTTP Client
 Host: api.twitter.com
 Accept: */*
 Authorization: 
    OAuth oauth_callback="http%3A%2F%2Flocalhost%2Fsign-in-with-twitter%2F",
          oauth_consumer_key="cChZNFj6T5R0TigYB9yd1w",
          oauth_nonce="ea9ec8429b68d6b77cd5600adbbb0456",
          oauth_signature="F1Li3tvehgcraF8DMJ7OyxO4w9Y%3D",
          oauth_signature_method="HMAC-SHA1",
          oauth_timestamp="1318467427",
          oauth_version="1.0"
我想把它转换成一个工作的HttpWebRequest。 到目前为止。我的代码看起来像这样

HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("https://api.twitter.com/oauth/request_token");

        ASCIIEncoding encoding = new ASCIIEncoding();

        httpReq.Method = "POST";
        httpReq.ContentType = "application/x-www-form-urlencoded";
        httpReq.Accept = "Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
不幸的是我已经走了这么远。。。我不知道这些请求是如何工作的。我需要包括其余的数据并拨打电话。但是我被卡住了。任何帮助都将不胜感激。

试试以下方法:

ASCIIEncoding encoder = new ASCIIEncoding();
byte[] data = encoder.GetBytes(serializedObject); // the data you wanted to send

HttpWebRequest request = new WebRequest.Create("https://api.twitter.com/oauth/request_token") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;

request.GetRequestCode().Write(data, 0, data.Length);
还有一个可能的疑问(类似问题):