I’m attempting to send an HTTP POST to a Rails 3 Application. Currently all I want to do is login from the C# client and receive a response in either XML or JSON.
Here is the controller code, I am using the Sorcery gem for the login.
class ClientSessionsController < ApplicationController
skip_before_filter :require_login, :except => [:create]
def create
if @user = login(params[:username],params[:password])
respond_to do |format|
format.xml { render :xml => @user }
format.json { render :json => @user }
end
else
respond_to do |format|
format.xml { render :xml => @user.errors, :status => 400 }
format.json { render :json => @users.errors, :status => 400 }
end
end
end
Initially I used the WebClient.UploadValues, however you cannot appear to be able to set the header for this request. So I tried using the WebRequest class in .NET.
I followed the example here:
However I simply received a 500 response.
Does anyone have any idea what I’m doing wrong or missing?
Thanks
Turns out I was receiving a 500 response due to a rouge require_login which I had in application.html.erb.
So my problem was nothing to do with the C#, and the code posted on the link above works perfectly if anyone else is having trouble doing something similar.