我需要從sinatra應用程序發送一個POST請求到一個rails應用程序,它會返回一些json。我在本地測試這個功能。網址如下:從sinatra應用程序發送一個post應用程序到rails應用程序
Rails app : railsapp.mydomain.com/api/v1.json
Sinatra app: sinatraapp.mydomain.com
在本地主機上,網址是:
Rails app: localhost:3000/api/v1.json
Sinatra app:localhost 3001
在我屈應用程序在本地運行,我有以下代碼,以使本地POST請求
$("#submit").click(function(){
$.post("http://localhost:3000/api/v1.json",
{email:"<email_here>",password:"<password_here>"},
function(data) {
//Do something with response
}
);
});
此外,請求標頭中的Content-Type
應爲"application/x-www-form-urlencoded"
。我在Firefox中使用REST客戶端來測試請求並且它可以工作,但是在上面的代碼中,請求並沒有被完成。我的代碼中有什麼錯誤?
謝謝你
是的,我用一個簡單的解決方法更新了答案。 –