Steam how to create new trade offer?

524 views Asked by At

If i have users invetntories and partnerurl for trade offer, how i can generate get request for trade offer? I have steamUserId, inventoryId and partnerurl in steambot i dont understand how it can be used. Can someone help me and give me real method?

Thanks

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

There are 0 answers