how to make a POST request?

0

It's the following, I'm using google api to build an app. But I came in this part below and I can not at all. How do I POST that he asks me? I already have all the parameter data.

Below the google help excerpt:

Supondo que o usuário tenha acesso a seu aplicativo, troque o código de autorização recebido na etapa 3 por um toque de atualização e um token de acesso. Envie uma solicitação POST para https://accounts.google.com/o/oauth2/token

Veja um exemplo de solicitação abaixo:

POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded

    code=4/ux5gNj-_mIu4DOD_gNZdjX9EtOFf&
    client_id=1084945748469-eg34imk572gdhu83gj5p0an9fut6urp5.apps.googleusercontent.com&
    client_secret=hDBmMRhz7eJRsM9Z2q1oFBSe&
    redirect_uri=http://localhost/oauth2callback&
    grant_type=authorization_code

And this POST was to return the following:

{
  "access_token" : "ya29.AHES6ZTtm7SuokEB-RGtbBty9IIlNiP9-eNMMQKtXdMP3sfjL1Fc",
  "token_type" : "Bearer",
  "expires_in" : 3600,
  "refresh_token" : "1/HKSmLFXzqP0leUihZp2xUt3-5wkU7Gmu2Os_eBnzw74"
}
    
asked by anonymous 30.09.2016 / 19:21

1 answer

1

Assuming the data you are going to send is in a variable called data :

var data = {
  code : "4/ux5gNj-_mIu4DOD_gNZdjX9EtOFf&",
  client_id :" 1084945748469-eg34imk572gdhu83gj5p0an9fut6urp5.apps.googleusercontent.com&",
  client_secret" : "hDBmMRhz7eJRsM9Z2q1oFBSe&",
  redirect_uri : "http://localhost/oauth2callback&",
  grant_type="authorization_code"
}

var request = new XMLHttpRequest();
request.open('POST', '/my/url', true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.send( data );

Reference: You might not need jQuery

    
30.09.2016 / 19:26