POST changes to GET

41 views
Skip to first unread message

Michael Chenetz

unread,
Jun 17, 2016, 10:28:45 AM6/17/16
to nodejs
I have a page that i am posting to and it redirects to another page. I understand that most servers will redirect a POST to a GET. How do i catch the redirect URL so that i can POST to it. Here is some example code below.

var req = https.request({
host: 'dashboard.meraki.com',
path: '/api/v0/networks/1234567/vlans/',
headers: {
'x-cisco-meraki-api-key': '12345678'
},
method: 'POST'
}, function (response) {
if (response.statusCode > 300 && response.statusCode < 400) {


}
console.log(response.headers);
response.on('data', (data)=> {
body += data;
});
response.on('end', ()=> {
response.write(body)
});
console.log(response);
});
req.write('');
req.end();

Thanks...

Mike

Ryan Graham

unread,
Jun 17, 2016, 4:30:36 PM6/17/16
to nodejs

If you are getting a redirect then there should be a Location header with a new path or URL in it. Use that to create a new request. It is up to you which HTTP method you use for that request.

~Ryan


--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/0969c55e-efbb-4ff5-bfd6-6459d4c556b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

~Ryan

Michael Chenetz

unread,
Jun 19, 2016, 8:17:43 PM6/19/16
to nodejs
Thanks... That's what i figured but i was hoping that there was a better way. ;-)
Reply all
Reply to author
Forward
0 new messages