Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var request = require('request');
- module.exports = {
- fetch: fetch,
- fetchTest: fetchTest
- };
- function fetch(url){
- return new Promise(function(resolve, reject) {
- request(url, function(error, response, html){
- if(error) {
- return reject(error);
- }
- if(response.statusCode !== 200){
- return reject(new Error('God bad status code from server'));
- }
- resolve(html);
- });
- });
- }
- function fetchTest(url){
- return new Promise(function(resolve, reject) {
- request({
- method: 'POST',
- uri: url,
- jar: true,
- form: {
- username: 'zeke',
- password: 'coys'
- },
- followAllRedirects: true
- }, function(error, response, html){
- if(error) {
- return reject(error);
- }
- if(response.statusCode !== 200){
- return reject(new Error('God bad status code from server'));
- }
- resolve(html);
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement