I'm trying to get a output from http://ift.tt/2cmtpnZ i will get all items with regex but my request is empty. I'm trying to get outpput with fetchrequest method
Fetch Request:
private string FetchRequest(string inpUrl, string inpMethod, string inpReferer, string inpHost, string inpAccept, NameValueCollection inpNvc, bool xml, bool autoRedirect)
{
using (var response = Request(inpUrl, inpMethod, inpReferer, inpHost, inpAccept, inpNvc, xml, autoRedirect))
{
_cookies.Add(response.Cookies);
using (var responseStream = response.GetResponseStream())
{
if (responseStream == null) return null;
using (var reader = new StreamReader(responseStream))
{
return reader.ReadToEnd();
}
}
}
}
Request method
private HttpWebResponse Request(string inpUrl, string inpMethod, string inpReferer, string inpHost, string inpAccept, NameValueCollection inpNvc, bool inpXml, bool autoRedirect)
{
var request = (HttpWebRequest)WebRequest.Create(inpUrl);
request.Accept = inpAccept;
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36";
request.Timeout = 20000;
request.Headers.Add("Accept-Language", "de,en-US;q=0.7,en;q=0.3");
request.AllowAutoRedirect = autoRedirect;
request.CookieContainer = _cookies;
request.Method = inpMethod;
//Volatile variables
if (inpHost != "")
{
request.Host = inpHost;
}
if (inpReferer != "")
{
request.Referer = inpReferer;
}
if (inpXml)
{
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
request.Headers.Add("X-Prototype-Version", "1.7");
request.Headers.Add("Cache-Control", "no-cache");
request.Headers.Add("Pragma", "no-cache");
}
if (inpMethod != "POST") return request.GetResponse() as HttpWebResponse;
var dataString = (inpNvc == null ? null : string.Join("&", Array.ConvertAll(inpNvc.AllKeys, key =>
HttpUtility.UrlEncode(key) +"=" + HttpUtility.UrlEncode(inpNvc[key])
)));
if (dataString == null) return request.GetResponse() as HttpWebResponse;
var dataBytes = Encoding.UTF8.GetBytes(dataString);
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.ContentLength = dataBytes.Length;
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(dataBytes, 0, dataBytes.Length);
}
return request.GetResponse() as HttpWebResponse;
}
My variables
public List<Item> AllListedItems(TradeType SellOrder)
{
List<Item> orders = new List<Item>();
var containsItems = true;
var baseUrl = "http://ift.tt/2bMuYXd" + _stackUser + "&page=";
var page = 1;
const string accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
const string host = "backpack.tf";
while (containsItems)
{
var url = baseUrl + page;
var responseBody = FetchRequest(url, "GET", "", host, accept, null, false, false);
.
.
.
Fetchrequest returns empty string.
Aucun commentaire:
Enregistrer un commentaire