POST
http パッケージを Web サイトに送信する際に問題が発生しました。送信前に何かが投稿コンテンツ データを混合していると思いますが、postdata
文字列は正常に見えます。これが私のメソッドコードです:
public ResponseData AdvancedRequest(string method, string url, string postdata, string proxydata, string referer, int timeout)
{
var req = WebRequest.Create(url) as HttpWebRequest;
req.Method = "GET";
IWebProxy myProxy = new WebProxy(proxydata.Split(':')[0], Convert.ToInt32(proxydata.Split(':')[1]));
req.Proxy = null;
//req.ServicePoint.ConnectionLimit = 1;
req.ProtocolVersion = HttpVersion.Version10;
req.KeepAlive = true;
//req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0";
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0";
req.AllowAutoRedirect = false;
req.Timeout = timeout*1000;
req.ReadWriteTimeout = timeout*1000;
req.ContentType = "application/x-www-form-urlencoded";
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
req.Headers.Add("Accept-Language", "en-US,en;q=0.5");
//req.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
req.Headers.Add("Accept-Encoding", "gzip, deflate");
//req.Headers.Add("cache-control", "max-age=0");
req.CookieContainer = _cookies;
//req.Headers.Add("Keep-Alive", "115");
//req.Connection = "keepalive";
if (!String.IsNullOrEmpty(referer))
{
req.Referer = referer;
}
req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
if (method == "POST")
{
req.Method = "POST";
req.ServicePoint.Expect100Continue = false;
System.Text.Encoding enc = System.Text.Encoding.UTF8;
var bytedata = enc.GetBytes(postdata);
req.ContentLength = bytedata.Length;
//Stream postStream = req.GetRequestStream();
try
{
using (var postStream = req.GetRequestStream())
{
postStream.Write(bytedata, 0, bytedata.Length);
postStream.Close();
}
}
catch (WebException except)
{
}
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse() as HttpWebResponse;
this._cookies.Add(resp.Cookies);
//resp.Close();
ResponseData rdata = new ResponseData(resp);
resp.Close();
return rdata;
//StreamReader strdr = new StreamReader(resp.GetResponseStream());
//string response = strdr.ReadToEnd();
//strdr.Close();
//return response;
}
正しい投稿データは次のとおりです。
session%5Busername_or_email%5D=LoginHere&session%5Bpassword%5D=PasswordHere&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=auth_token_here
ここに私が持っている間違った投稿データがあります:
session%5Busername_or_email%5D=AsyncCallback&session%5Bpassword%5D=De2zmcc6093&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=0e67f8df715c79f81a9b2be203848ad7f805b21csession%5Busername_or_email%5D=AsyncCallback&session%5Bpassword%5D=De2zmcc6093&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=0e67f8df715c79f81a9b2be203848ad7f805b21c
の値postdata
は次のとおりです。
session%5Busername_or_email%5D=ログイン&session%5Bpassword%5D=パスワード&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=0e67f8df715c79f81a9b2be203848ad7f805b21c