POST Rest Service POST method does not work in Fiddler

I use WCF Restservice for user authentication. I have a POST method and it works fine with jquery, but it fails when testing Fiddler. I get 415 Unsupported Media Type.

Here is my code

[OperationContract] [WebInvoke(Method = "POST", UriTemplate = "Login", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] public string Login(string userName, string password) { string valid; // Log in user int authenticatedId = AuthenticateManager.Authenticate(userName, password); if (authenticatedId != -1) { valid = "Welcome " + userName + "!"; } else { valid = "Login failed!"; } return valid; } 

This is what I pass in the body of Fiddler

 [{ "userName":"dusshyi", "password":"subram1" }] 

This is what fiddler creates

  <HTML><HEAD><STYLE type="text/css">#content{ FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em; MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: #000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: white}P{MARGIN-TOP: 0px; MARGIN-BOTTOM: 12px; COLOR: #000000; FONT-FAMILY: Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f0f0e0 1px solid; MARGIN-TOP: -5px; PADDING-LEFT: 5px; FONT-SIZE: 1.2em; PADDING-BOTTOM: 5px; BORDER-LEFT: #f0f0e0 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: #f0f0e0 1px solid; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e5e5cc}.heading1{MARGIN-TOP: 0px; PADDING-LEFT: 15px; FONT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 3px; MARGIN-LEFT: -30px; WIDTH: 100%; COLOR: #ffffff; PADDING-TOP: 10px; FONT-FAMILY: Tahoma; BACKGROUND-COLOR: #003366}.intro{MARGIN-LEFT: -15px}</STYLE> <TITLE>Service</TITLE></HEAD><BODY> <DIV id="content"> <P class="heading1">Service</P> <BR/> <P class="intro">Endpoint not found.</P> </DIV> </BODY></HTML> 

Please, help!

+6
source share
3 answers

Have the Content-Type content of the application/json request been set in the Fiddler request body editor?

enter image description here

+13
source

I had the same problem this morning ...

It was fixed for me to click on the “Composer” tab and then add the following to the “Request Headers” section:

 Content-Type: application/x-www-form-urlencoded 

Without this line, I noticed that the log showed that he was trying to call my REST service using the Content-Type "text / html", and the Service would not be called.

This can happen if I add the line:

 Content-Type: application/json 

However, after adding the line " Content-Type: application / x-www-form-urlencoded ", Fiddler will now call this service with the content type " application / json ", and the web service has been called correctly. Strange ...

I created a full walk by creating a WCF JSON web service and testing it with Fiddler on the following page:

http://mikesknowledgebase.com/pages/Services/WebServices-Page1.htm

+3
source

Fiddler Web Debugger Debugger: Composer section; Parameters

 Parsed POST,../Service.svc/Login,HTTP/1.1 Request Header: User-Agent: Fiddler Content-Type: application/json;charset=UTF-8 Host: localhost:15021 Content-Length: 43 Request Body: {"username":"ABC","password":"pwd"} 

and then do

+1
source

Source: https://habr.com/ru/post/896426/


All Articles