Instagramからデータを取得するために使用しようとしているC#にWebRequest
があります。 WebRequestはThe remote server returned an error: (403) Forbidden.
をスローしますが、cURLコマンドはHTMLを返します。実際には、私のPOSTフォームデータは長くなり、JSONを返します。C#WebRequestではなくエラー403を返します
C#
String uri = "https://www.instagram.com/query/";
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
string postData = "q=ig_user(1118028333)";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(postData);
// Set the content type of the data being posted.
request.ContentType = "application/x-www-form-urlencoded";
// Set the content length of the string being posted.
request.ContentLength = byte1.Length;
using (var dataStream = request.GetRequestStream())
{
dataStream.Write(byte1, 0, byte1.Length);
}
try
{
var x = (HttpWebResponse)request.GetResponse();
}
catch (WebException wex)
{
String wMessage = wex.Message;
}
(Windowsの場合)のcURL
curl "https://www.instagram.com/query/" --data "q=ig_user(1118028333)"
返しHTMLエラー403
をスローします。
FireFoxのリクエストボディ、メソッド= POSTは、何のヘッダ
q=ig_user(1118028333)
返しHTML
なぜWebRequestクラスは、cURLのか、FireFoxのエラー403をスローしませんが、ないでしょうか?データを取得するためにC#で何ができますか?