Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request Body of POST method in Fiddler2

Tags:

wcf

The method call is successful without Request body. When I use below Request body, I get HTTP/1.1 400 Bad Request. Do you see any obvious problem with below requst body?

Request Body

{ 
    "_userConfigData":{"UserName":"bXZpbmphbXVyaQ==", "FirstName":"User1", "LastName":"Last1", "ContactInfo":"None" }, 
    "_configResult": "Miscellaneous"
}

Request Headers

User-Agent: Fiddler
Content-Type: application/json
Host: localhost:1706
Content-Length: 167

Here is the server side method:

[OperationContract]
[WebInvoke(UriTemplate = "UpdateUserDetails/?_clientIP={_clientIP}&AdminName={AdminName}", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] 
public void UpdateUserDetails(UserConfigData _userConfigData, ConfigResult _configResult, string _clientIP, string AdminName)
{
    // 
}

Here is the URL that I use with Fiddler2:

http://localhost:1706/WCF/UserConfig/UserConfigService.svc/UpdateUserDetails?_clientIP=localhost&AdminName=admin

Thanks,

like image 500
codematrix Avatar asked Dec 13 '22 05:12

codematrix


2 Answers

I changed my service like the posting above and it did not work until I noticed the first screen shot provided. In the fiddler header is the line

Content-Type: application/json

This allowed me to send data to the service. After changing the return type to string I was able to get raw data back.

like image 171
Tom Smith Avatar answered Jan 26 '23 06:01

Tom Smith


I was able to get your code to work, but I had to make some modifications.

  1. I had to move the data carried by the query string into the body itself, otherwise it didn't work.
  2. I had to get rid of the BodyStyle Wraped option.

Anyway, here is the updated model objects with your data:

public class UserConfigData
{
    public string UserName { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string ContactInfo { get; set; }
}

public class Result
{
    public UserConfigData UserConfigData { get; set; }
    public string ConfigResult { get; set; }
    public string ClientIp { get; set; }
    public string AdminName { get; set; }
}

The server side method:

[WebInvoke(UriTemplate = "UpdateUserDetails", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
public void UpdateUserDetails(Result result)
{
    //
}

The json that you pass in:

{
    "AdminName":"String content",
    "ClientIp":"String content",
    "ConfigResult":"String content",
    "UserConfigData":{
        "ContactInfo":"String content",
        "FirstName":"String content",
        "LastName":"String content",
        "UserName":"String content"
    }
}

UPDATE: Fiddler request screen shot: Fiddler request screen shot

And the request gets to the server UpdateUserDetails() Handler: UpdateUserDetails

like image 27
Bojin Li Avatar answered Jan 26 '23 07:01

Bojin Li