2015-11-20 54 views
0

我有一個以前工作的離子應用程序,談話節點服務器運行socket.io服務器。離子角應用程序發送POST到socket.io服務器

套接字服務器獲取POST,但它是空的。它曾經完美地工作。

我可以使用REST客戶端(PAW在mac上)成功發送,沒有問題...... POST主體在socket.io應用程序中被接收。

下面是我的離子應用的角度代碼:

var data = { username: 'bob', password: 'smith' } 

var config = { 
     headers : { 
     'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;' 
     } 
    } 
    $http.post('http://example.com:3000/login',data, config) 

    .success(function(result) { 
      //don't make it here 

    }).error(function(data,status) { 
     //make it here... no error code 
    }); 

,並在節點服務器上我socket.io應用:

app.post('/login', function (req, res) { 
    console.log(req.body); //this is empty 
    console.log("req.body.username: " + req.body.username); //empty empty 
}); 

確認,app.post不執行.. .se我們在服務器上做到這一點。但身體是空的。

預檢問題?我難倒...需要這方面的工作:(今晚

+0

我應該提到..這種行爲同時發生在瀏覽器(離子服務)和ios設備上(離子建設ios - > xcode在設備上運行),所以它真的不能成爲CORS問題。 – lilbiscuit

+0

進度...我改成配置爲'''Content-Type':'application/x-www-form-urlencoded',現在我在服務器上得到一些數據。控制檯日誌輸出:'{'{「username」:「bob」,「password」:「smith」}':'' req.body.username:undefined' – lilbiscuit

回答

0

的$ http.post功能需要(url, data, [config])作爲參數 參考:Documentation

通過看你的代碼,我認爲弄丟了參數

請嘗試以下

var data = { username: 'bob', password: 'smith' } 

var config = { 
    headers : { 
    'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;' 
    } 
} 
$http.post('http://example.com:3000/login', data, config) 
.success(function(result) { 
    //don't make it here 

}).error(function(data,status) { 
    //make it here... no error code 
}); 
+0

我糾正了我的問題......那只是一個錯字。 – lilbiscuit

相關問題