1

I have following code at javascript(node) and want to convert it to curl

const body = {
  'Email': "my email:)",
  'EncryptedPasswd': "my encrypted pass",
  'service': 'androidmarket',
  'accountType': 'HOSTED_OR_GOOGLE',
  'has_permission': '1',
  'source': 'android',
  'androidId': "my id",
  'app': 'com.android.vending',
  'device_country': 'us',
  'operatorCountry': 'us',
  'lang': 'en_US',
  'sdk_version': '23'
};

return _request.postAsync({url: _opts.loginUrl, gzip: true, json: false, form: body})
  .spread(function (res, body) {
    if (res.statusCode !== 200) {
      throw new LoginError(body);
    }
    assert(res.statusCode === 200, 'login failed');
    assert(res.headers['content-type'] === 'text/plain; charset=utf-8', 'utf8 string body');
    const response = responseToObj(body);
    if (!response || !response.auth) {
      throw new Error('expected auth in server response');
    }

    // set the auth token member to the response token.
    _opts.authToken = response.auth;
    return response.auth;
  });

And my curl request here:

curl --data "Email==myemail&EncryptedPasswd=mypass&has_permission=1&accountType=HOSTED_OR_GOOGLE&add_account=1&service=androidmarket&has_permission=1&source=android&device_country=us&lang=en_US&sdk_version=23&androidId=3c816e5b68106eb2&app=com.android.vending&operatorCountry=us" https://android.clients.google.com/auth

I tried many times run javascript script and always worked. And i can't see any difference between those script but js code works, curl doesn't

2
  • What does your curl request returns? Commented May 11, 2018 at 18:11
  • What do you mean with curl doesn't work? Do you get an error message? What seems to be the problem? Commented May 11, 2018 at 18:27

2 Answers 2

1

According to your JavaScript, it is a POST request, which you haven't specified in your curl command.

curl \
-X POST \
--data "Email==myemail&EncryptedPasswd=mypass&has_permission=1&accountType=HOSTED_OR_GOOGLE&add_account=1&service=androidmarket&has_permission=1&source=android&device_country=us&lang=en_US&sdk_version=23&androidId=3c816e5b68106eb2&app=com.android.vending&operatorCountry=us" \
https://android.clients.google.com/auth

Here is the syntax:

curl -X POST -d '&param1=1&param2=2...' URL
Sign up to request clarification or add additional context in comments.

1 Comment

The --data implies a POST as the docs states: "Sends the specified data in a POST request".
0

To make it easier to read, I would place each field on a separate line. You need a slash to separate each line.

In the question you have two equal signs for the email (Email==myemail). Could that be it? Also having these fields separate like this and putting them in the same order as the JavaScript fields could help you compare the two lists and make sure they are indeed equal.

curl --data "Email=myemail" \
     --data "EncryptedPasswd=mypass" \
     --data "has_permission=1" \
     --data "accountType=HOSTED_OR_GOOGLE" \
     --data "add_account=1" \
     --data "service=androidmarket" \
     --data "has_permission=1" \
     --data "source=android" \
     --data "device_country=us" \
     --data "lang=en_US" \
     --data "sdk_version=23" \
     --data "androidId=3c816e5b68106eb2" \
     --data "app=com.android.vending" \
     --data "operatorCountry=us" \
         https://android.clients.google.com/auth

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.