从sinatra应用程序向Rails应用程序发出发布请求

我需要从sinatra应用程序向rails应用程序发送POST请求,该请求将返回一些json.我在本地测试此功能.网址如下:

I need to send a POST request from a sinatra app to a rails app which would return back some json. Im testing this functionality locally. The urls are as follows:

Rails app : railsapp.mydomain.com/api/v1.json
Sinatra app: sinatraapp.mydomain.com

在localhost上,URL为:

On localhost, the urls are:

Rails app: localhost:3000/api/v1.json
Sinatra app:localhost 3001

在本地运行的sinatra应用程序中,我具有以下代码以在本地发出POST请求

In my sinatra app running locally, i have the following code to make the POST request locally

$("#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 Client来测试请求,该请求可以正常工作,但是在上面的代码中根本没有发出请求.我的代码有什么错误?

Also, the Content-Type in the request header should be "application/x-www-form-urlencoded". I used REST Client in Firefox to test the request and it works, but in the above code the request is not being made at all. What is the error in my code ?

谢谢



 1 条回答