我需要从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客户端来测试请求并且它可以工作,但是在上面的代码中,请求并没有被完成。我的代码中有什么错误?
谢谢你
是的,我用一个简单的解决方法更新了答案。 –