VijayMathew
VijayMathew

Reputation: 55

Restful WCF service POST methods returns HTTP400 error in fiddler2

have created simple Restful service for log in verification. Following are my interface and class definitions.

Interface IDemo:

public interface IDemo
{
    [OperationContract]
    [WebInvoke(RequestFormat = WebMessageFormat.Json,
               ResponseFormat = WebMessageFormat.Json,
               BodyStyle = WebMessageBodyStyle.Bare,
               UriTemplate = "/ValidateUser?Username={UserName}&Password={Password}",
               Method = "POST")]
    string  ValidateUser(string Username, string Password);
}

Class Demo :

public class Demo:IDemo
{
    public string ValidateUser(string Username, string Password)
    {
        Users objUser = new Users();
        objUser.UserID = Username;
        objUser.Password = Password;
        string Msg = LoginDataService.ValidateUser(Username, Password);
        return Msg;
    }
}

localhost:49922/Demo.svc/ValidateUser?Username=demo&Password=demo (with http:\)

When I try to parse the above URL under the Post Method in Fiddler2 I got Bad Request HTTP400 error.

Can anyone help me what is wrong in my code.

Thanks & Regards,

Vijay

Upvotes: 0

Views: 902

Answers (2)

Rajesh
Rajesh

Reputation: 7886

For the above REST method the POST from Fiddler needs to be as shown below:

POST http://localhost/Sample/Sample.svc/ValidateUser?Username=demo&Password=demo HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: rajeshwin7
Content-Length: 0

Doing so i get back a 200 OK HTTP Status as shown below:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 44
Content-Type: application/json; charset=utf-8
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 14 Jun 2012 15:35:28 GMT

"Server returns username demo with password demo"

Upvotes: 0

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65461

Your URI template looks like you are sending the parameters in the URL. But when you use POST the parameters are sent in the http body.

Note you should not send the username and passord in the url as it can be logged.

Upvotes: 1

Related Questions