Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ { cityPK: { name: 'Lodi', region: 'Lombardia' } },
- { cityPK: { name: 'Frosinone', region: 'Lazio' } },
- { cityPK: { name: 'Roma', region: 'Lazio' } },
- { cityPK: { name: 'Tivoli', region: 'Lazio' } } ]
- var http = require('http');
- var request = require('request');
- var express = require('express');
- var bodyParser = require('body-parser');
- var app = express();
- app.use(bodyParser.urlencoded({extended:false}));
- app.use(bodyParser.json());
- app.post('/login',function(req,res){
- console.log("sono nella post "+req.body.username);
- var uid = req.body.username;
- var upwd = req.body.password;
- res.setHeader('Content-Type', 'application/json');
- res.header("Access-Control-Allow-Origin", "*");
- res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
- res.header("Access-Control-Allow-Credentials", true);
- request({
- url: "http://localhost:8080/RestServiceAdmin/webresources/entities.city",
- method: "GET",
- json: true ,
- headers:[{'content-type': 'application/json'}]
- }, function (error, response, body){
- if(!error & response.statusCode === 200){
- res.json(body);
- }
- });
- });
- app.listen(9080,function(){
- console.log('Server running at http://127.0.0.1:9080/');
- });
- var app = angular.module('myApp',[]);
- app.controller('myCtrl',function($scope,$http){
- $scope.check = function(data){
- var id = data.form.id;
- var pwd = data.form.password;
- console.log("utente è "+id+",password è "+pwd);
- var msg = {username: id,password: pwd};
- $http({
- url:'http://localhost:9080/login', //senza niente qui,metti * in app.post()
- method:"POST",
- data: $.param(msg),
- responseType: "application/json",
- headers: {'Content-Type': 'application/x-www-form-urlencoded',
- 'Accept': 'application/json'
- }})
- .then(function(response){
- console.log("Server response "+response.data);
- });
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement