Jump to content


Photo

Identical http request returns success: 2 (generic fail) instead of success: 1

node.js node-steamcommunity

Best Answer Royalgamer06 , 13 May 2018 - 07:41 AM

I adjusted my code to use sessionid provided by the webSession event instead, and now my code is fully working. Somehow community.getSessionID() was the blame for providing me the wrong sessionid.

Go to the full post


  • Please log in to reply
8 replies to this topic

#1 Royalgamer06

Royalgamer06

    Advanced Member

  • Member
  • PipPipPip
  • 87 posts

Posted 08 May 2018 - 09:08 PM

So, I am trying to do some curator stuff with node-steamcommunity.

However, for some reason, my simulated requests failed.

For example:

    const formdata = {
        sessionid: community.getSessionID(),
        clanid: offer.clanid,
        appid: offer.appid,
        action: `accept`
    };
    user.once(`webSession`, () => community.httpRequestPost({
        url: `https://store.steampowered.com/curator/${offer.clanid}/admin/ajaxrespondoffer`,
        form: formdata,
        // jar: jar,
        headers: {
            // ":authority": `store.steampowered.com`,
            // ":method": `POST`,
            // ":path": `/curator/${offer.clanid}/admin/ajaxrespondoffer`,
            // ":scheme": `https`,
            "Accept": `*/*`,
            "Accept-Encoding": `gzip, deflate, br`,
            //"accept-language": `nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7`,
            "Content-Length": `77`,
            "Content-Type": `application/x-www-form-urlencoded; charset=UTF-8`,
            "Cookie": community._jar.getCookieString(`https://store.steampowered.com`),
            "DNT": `1`,
            "Origin": `https://store.steampowered.com`,
            "Referer": `https://store.steampowered.com/curator/${offer.clanid}/admin/pending`,
            //"user-agent": `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36`,
            "X-Requested-With": `XMLHttpRequest`
        }
    }, acceptedCuratorConnectOffer));
    user.webLogOn();

I tried to experiment with headers, but that doesn't seem to do anything. Could it be because of https? Or protocol being h2?


Edited by Royalgamer06, 09 May 2018 - 04:40 AM.


#2 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 1,815 posts

Posted 08 May 2018 - 10:39 PM

You're probably meant to send a POST, which it doesn't seem like you're doing.



#3 Royalgamer06

Royalgamer06

    Advanced Member

  • Member
  • PipPipPip
  • 87 posts

Posted 09 May 2018 - 04:43 AM

You're probably meant to send a POST, which it doesn't seem like you're doing.

Actually I was, I just forgot to add it to the example code above.



#4 Royalgamer06

Royalgamer06

    Advanced Member

  • Member
  • PipPipPip
  • 87 posts

Posted 10 May 2018 - 10:19 AM

I could setup a teamviewer session, so you can help me debug and fix the problem? I'm really clueless. 



#5 Royalgamer06

Royalgamer06

    Advanced Member

  • Member
  • PipPipPip
  • 87 posts

Posted 12 May 2018 - 01:58 PM

I noticed the cookie sessionid and sessionid provided from getSessionID were different. So that's probably it. Now, I have to figure out how to fix and test it.



#6 Royalgamer06

Royalgamer06

    Advanced Member

  • Member
  • PipPipPip
  • 87 posts

Posted 13 May 2018 - 06:23 AM

There are some strange stuff happening. So, I got to admit I am not using community.httpRequestPost, instead I am using my own instance of request, but I do this:

user.on(`webSession`, (sessionID, cookies) => {
    logger.info(`Got steam web session`);
    community.setCookies(cookies);
    store.setCookies(cookies);
    //jar = Object.assign(jar, community._jar);
    //cookies.forEach(c => jar.setCookie(request.cookie(c), `https://steamcommunity.com`));
    // for (let domain in community._jar._jar.store.idx) {
    //     jar._jar.store.idx[domain] = community._jar._jar.store.idx[domain];
    // }
    cookies.forEach(cookie => {
        jar.setCookie(cookie, `https://steamcommunity.com`);
        jar.setCookie(cookie, `https://store.steampowered.com`);
        jar.setCookie(cookie, `https://help.steampowered.com`);
    });
});

And jar being used in my request defaults:

request = request.defaults({
        jar: jar,
        headers: {
            "User-Agent": `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36`,
            "Accept-Language": `nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7`
        },
        followAllRedirects: true
    }),

In addition, I use the code posted in the OP (but using my own instance of request).

So, here is the weird part. This is the request I end up making:
 

HEADERS 
{ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
  'Accept-Language': 'nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7',
  Accept: '*/*',
  'Accept-Encoding': 'gzip, deflate, br',
  'Content-Length': '77',
  'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  Cookie: 'sessionid=6c64xxxac7e2; steamLogin=76561198042965266%7c%7c02106545C272D8AC6FC1D70235CC18D36C89C418; steamLoginSecure=7656119xxx%7c%7c0E7Axxx1F036; browserid=126xxx487; Steam_Language=english; sessionid=6c64xxxc7e2; steamLogin=7656119xxx%7c%7c0210xxxC418; steamLoginSecure=7656119xxx%7c%7c0E7AxxxF036; browserid=126xxx487; Steam_Language=english',
  DNT: '1',
  Origin: 'https://store.steampowered.com',
  Referer: 'https://store.steampowered.com/curator/31xxx23/admin/pending',
  'X-Requested-With': 'XMLHttpRequest' }
BODY
{ sessionid: '0252xxx692b',
  clanid: 31xxx23,
  appid: 62xx00,
  action: 'accept' }

Notice how the cookies appear twice and the sessionid's are different between headers (pulled from jar) and body (pulled from getSessionID).



#7 Royalgamer06

Royalgamer06

    Advanced Member

  • Member
  • PipPipPip
  • 87 posts

Posted 13 May 2018 - 07:00 AM

I added some debug to on('webSession') to log its cookies and community and it was different every time.

Then I realized it was happening because it wasn't synchronous.
Allow me to explain:
On every webSession event, the cookies are refreshed and stored. However, I wasn't waiting for this to happen, instead I used webLogon and user.once(`webSession`), which caused my client code to happen simultaneously while cookies are refreshed and stored.



#8 Royalgamer06

Royalgamer06

    Advanced Member

  • Member
  • PipPipPip
  • 87 posts

Posted 13 May 2018 - 07:33 AM

There still seems to be a problem with node-steamcommunity though.

Even when I wait for setCookies to take place before I send any http request, community.getSessionID() still manages to return the wrong sessionid.



#9 Royalgamer06

Royalgamer06

    Advanced Member

  • Member
  • PipPipPip
  • 87 posts

Posted 13 May 2018 - 07:41 AM   Best Answer

I adjusted my code to use sessionid provided by the webSession event instead, and now my code is fully working. Somehow community.getSessionID() was the blame for providing me the wrong sessionid.







Also tagged with one or more of these keywords: node.js, node-steamcommunity

3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users