Steam如何创建新的交易报价?

时间:2015-06-09 13:38:40

标签: javascript c# asp.net-mvc get

如果我有用户invetntories和partnerurl的交易报价,我如何产生获得交易要求的请求? 我在steambot中有steamUserId,inventoryId和partnerurl,我不明白它是如何使用的。有人可以帮助我并给我真正的方法吗?

由于

Dictionary<string, string> paramss = new Dictionary<string, string>();

paramss.Add("sessionid", Request.Cookies["ASP.NET_SessionId"].Value);
paramss.Add("serverid", "1");
paramss.Add("partner", "76561198219142748");
paramss.Add("tradeoffermessage", "Hi");

string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");

HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("https://steamcommunity.com/tradeoffer/new/send");
myReq.Method = "POST";
myReq.CachePolicy = new     System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
myReq.Referer = "https://steamcommunity.com/tradeoffer/new/?partner=258877020&token=PClnSGtm";
myReq.ContentType = "multipart/form-data; boundary=" + boundary;


Stream memStream = new System.IO.MemoryStream();
string formdataTemplate = "\r\n--" + boundary + "\r\nContent-Disposition: {0}; name=\"{1}\";\r\n\r\n{2}";

foreach (string key in paramss.Keys)
{
    string formitem = string.Format(formdataTemplate, "form-data", key, paramss[key]);
    byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
    memStream.Write(formitembytes, 0, formitembytes.Length);
}

{
    string requestJSON =  @"{""newversion"":true,""version"":3,""me"":{""assets"":[{""appid"":570,""contextid"":""2"",""amount"":1,""assetid"":""6312245157""} ,{""appid"":570,""contextid"":""2"",""amount"":1,""assetid"":""6312245173""}],""currency"":[],""ready"":true},""them"":{""assets"":[],""currency"":[],""ready"":true}}";

    string formitem = string.Format(formdataTemplate, "form-data", "json_tradeoffer", requestJSON);
    byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
    memStream.Write(formitembytes, 0, formitembytes.Length);
}

{
   string requestJSON =  @"{}";

    string formitem = string.Format(formdataTemplate, "form-data", "trade_offer_create_params", requestJSON);
    byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
    memStream.Write(formitembytes, 0, formitembytes.Length);
}

myReq.ContentLength = memStream.Length;

Stream requestStream = myReq.GetRequestStream();

memStream.Position = 0;
byte[] tempBuffer = new byte[memStream.Length];
memStream.Read(tempBuffer, 0, tempBuffer.Length);
memStream.Close();
requestStream.Write(tempBuffer, 0, tempBuffer.Length);
requestStream.Close();


var response = (HttpWebResponse)myReq.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
    var result = streamReader.ReadToEnd();
}

0 个答案:

没有答案