How to test a web api post method which receives a classWeb API 2 POST request simulation in POSTMAN Rest ClientWeb API Post Method not workingHow do I test for an empty JavaScript object?How to make HTTP POST web requestHow do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?WCF vs ASP.NET Web APIHow do I get ASP.NET Web API to return JSON instead of XML using Chrome?How to secure an ASP.NET Web APIHow to pass json POST data to Web API method as an object?Postman Testing send string to Web Api accepting string is nullPOST from Typescript to Web API API, unable to pass a JSON ObjectUnable to test the create webapi method using Postman
Is it moral to remove/hide certain parts of a photo, as a photographer?
Why isn't the new LEGO CV joint available on Bricklink or Brickowl?
Proof of First Difference Property for Fourier Series
Difference between "jail" and "prison" in German
What does Argus Filch specifically do?
How do I safety check that there is no light in Darkroom / Darkbag?
A criterion for finite abelian group to embed into a symmetric group
Meaning of ギャップ in the following sentence
Can an unintentional murderer leave Ir Miklat for Shalosh Regalim?
What is the reason behind water not falling from a bucket at the top of loop?
Why does the friction act on the inward direction when a car makes a turn on a level road?
Partial Fractions: Why does this shortcut method work?
Skipping same old introductions
A wiild aanimal, a cardinal direction, or a place by the water
How does Rust's 128-bit integer `i128` work on a 64-bit system?
Accurately recalling the key - can everyone do it?
Is there any difference between "result in" and "end up with"?
Deflecting lasers with lightsabers
In a KP-K endgame, if the enemy king is in front of the pawn, is it always a draw?
Unlocked Package Dependencies
Is law enforcement responsible for damages made by a search warrant?
Can I say "Gesundheit" if someone is coughing?
HackerRank Implement Queue using two stacks Solution
Detect lightning:recordForm change in mode attribute
How to test a web api post method which receives a class
Web API 2 POST request simulation in POSTMAN Rest ClientWeb API Post Method not workingHow do I test for an empty JavaScript object?How to make HTTP POST web requestHow do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?WCF vs ASP.NET Web APIHow do I get ASP.NET Web API to return JSON instead of XML using Chrome?How to secure an ASP.NET Web APIHow to pass json POST data to Web API method as an object?Postman Testing send string to Web Api accepting string is nullPOST from Typescript to Web API API, unable to pass a JSON ObjectUnable to test the create webapi method using Postman
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have created an ASP.NET web API which has a controller named ImageSaveController
. This has an InsertImage
method which inserts data into database and is an HttpPost
method. This method receives an object of type ImageData
as a parameter. The code for the controller and the parameter class are given below:
public class ImageSaveController : ApiController
[HttpPost]
public IHttpActionResult InsertImage(ImageData imageData)
System.Data.SqlClient.SqlConnection conn = null;
try
//Image save to database code here
catch (Exception ex)
return Content(HttpStatusCode.NotModified, ex.Message);
finally
if (conn != null)
conn.Close();
return Content(HttpStatusCode.OK,"");
//ImageData class
public class ImageData
public int Id get; set;
public byte[] ImageValue get; set;
I would like to test it from a client. As you can notice, the ImageValue
property of the ImageData
class is a byte
array. Not sure how to pass the C# class parameter to this method. Ideally I would like to pass the parameter as json
and I am not sure how to construct the json
for this purpose. I am also not sure whether it could be tested using the chrome app called postman.
c# json asp.net-web-api postman
add a comment |
I have created an ASP.NET web API which has a controller named ImageSaveController
. This has an InsertImage
method which inserts data into database and is an HttpPost
method. This method receives an object of type ImageData
as a parameter. The code for the controller and the parameter class are given below:
public class ImageSaveController : ApiController
[HttpPost]
public IHttpActionResult InsertImage(ImageData imageData)
System.Data.SqlClient.SqlConnection conn = null;
try
//Image save to database code here
catch (Exception ex)
return Content(HttpStatusCode.NotModified, ex.Message);
finally
if (conn != null)
conn.Close();
return Content(HttpStatusCode.OK,"");
//ImageData class
public class ImageData
public int Id get; set;
public byte[] ImageValue get; set;
I would like to test it from a client. As you can notice, the ImageValue
property of the ImageData
class is a byte
array. Not sure how to pass the C# class parameter to this method. Ideally I would like to pass the parameter as json
and I am not sure how to construct the json
for this purpose. I am also not sure whether it could be tested using the chrome app called postman.
c# json asp.net-web-api postman
add a comment |
I have created an ASP.NET web API which has a controller named ImageSaveController
. This has an InsertImage
method which inserts data into database and is an HttpPost
method. This method receives an object of type ImageData
as a parameter. The code for the controller and the parameter class are given below:
public class ImageSaveController : ApiController
[HttpPost]
public IHttpActionResult InsertImage(ImageData imageData)
System.Data.SqlClient.SqlConnection conn = null;
try
//Image save to database code here
catch (Exception ex)
return Content(HttpStatusCode.NotModified, ex.Message);
finally
if (conn != null)
conn.Close();
return Content(HttpStatusCode.OK,"");
//ImageData class
public class ImageData
public int Id get; set;
public byte[] ImageValue get; set;
I would like to test it from a client. As you can notice, the ImageValue
property of the ImageData
class is a byte
array. Not sure how to pass the C# class parameter to this method. Ideally I would like to pass the parameter as json
and I am not sure how to construct the json
for this purpose. I am also not sure whether it could be tested using the chrome app called postman.
c# json asp.net-web-api postman
I have created an ASP.NET web API which has a controller named ImageSaveController
. This has an InsertImage
method which inserts data into database and is an HttpPost
method. This method receives an object of type ImageData
as a parameter. The code for the controller and the parameter class are given below:
public class ImageSaveController : ApiController
[HttpPost]
public IHttpActionResult InsertImage(ImageData imageData)
System.Data.SqlClient.SqlConnection conn = null;
try
//Image save to database code here
catch (Exception ex)
return Content(HttpStatusCode.NotModified, ex.Message);
finally
if (conn != null)
conn.Close();
return Content(HttpStatusCode.OK,"");
//ImageData class
public class ImageData
public int Id get; set;
public byte[] ImageValue get; set;
I would like to test it from a client. As you can notice, the ImageValue
property of the ImageData
class is a byte
array. Not sure how to pass the C# class parameter to this method. Ideally I would like to pass the parameter as json
and I am not sure how to construct the json
for this purpose. I am also not sure whether it could be tested using the chrome app called postman.
c# json asp.net-web-api postman
c# json asp.net-web-api postman
edited Mar 27 at 1:22
Dale Burrell
4,2825 gold badges27 silver badges57 bronze badges
4,2825 gold badges27 silver badges57 bronze badges
asked Jul 17 '16 at 7:10
MasseyMassey
4961 gold badge9 silver badges23 bronze badges
4961 gold badge9 silver badges23 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Open postman enter your url to the action:
Add header: Content-Type - application/json.
In body tab check "raw" (JSON) and type your data.
POST /api/ImageSave/InsertImage/ HTTP/1.1
Host: localhost:32378
Content-Type: application/json
Cache-Control: no-cache
"id" : 1,
"imageValue" : [11,141,123,121]
source Web API 2 POST request simulation in POSTMAN Rest Client
If you want to make good tests, the better solution is to write unit tests.
add a comment |
This is what I use to do:
Use a REST client tester like Postman or Fiddler. I use Postman which is an app for Google Chrome.
For easy construction of JSON you can create a HttpGet method on you controller and return a fake constructed ImageData
and call it from Postman. Here you will see the JSON and use that for input to the POST method.
public class ImageSaveController : ApiController
public ImageData Get()
return new ImageData
// insert test data here
;
[HttpPost]
public IHttpActionResult InsertImage(ImageData imageData)
System.Data.SqlClient.SqlConnection conn = null;
try
//Image save to database code here
catch (Exception ex)
return Content(HttpStatusCode.NotModified, ex.Message);
finally
if (conn != null)
conn.Close();
return Content(HttpStatusCode.OK,"");
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38418787%2fhow-to-test-a-web-api-post-method-which-receives-a-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Open postman enter your url to the action:
Add header: Content-Type - application/json.
In body tab check "raw" (JSON) and type your data.
POST /api/ImageSave/InsertImage/ HTTP/1.1
Host: localhost:32378
Content-Type: application/json
Cache-Control: no-cache
"id" : 1,
"imageValue" : [11,141,123,121]
source Web API 2 POST request simulation in POSTMAN Rest Client
If you want to make good tests, the better solution is to write unit tests.
add a comment |
Open postman enter your url to the action:
Add header: Content-Type - application/json.
In body tab check "raw" (JSON) and type your data.
POST /api/ImageSave/InsertImage/ HTTP/1.1
Host: localhost:32378
Content-Type: application/json
Cache-Control: no-cache
"id" : 1,
"imageValue" : [11,141,123,121]
source Web API 2 POST request simulation in POSTMAN Rest Client
If you want to make good tests, the better solution is to write unit tests.
add a comment |
Open postman enter your url to the action:
Add header: Content-Type - application/json.
In body tab check "raw" (JSON) and type your data.
POST /api/ImageSave/InsertImage/ HTTP/1.1
Host: localhost:32378
Content-Type: application/json
Cache-Control: no-cache
"id" : 1,
"imageValue" : [11,141,123,121]
source Web API 2 POST request simulation in POSTMAN Rest Client
If you want to make good tests, the better solution is to write unit tests.
Open postman enter your url to the action:
Add header: Content-Type - application/json.
In body tab check "raw" (JSON) and type your data.
POST /api/ImageSave/InsertImage/ HTTP/1.1
Host: localhost:32378
Content-Type: application/json
Cache-Control: no-cache
"id" : 1,
"imageValue" : [11,141,123,121]
source Web API 2 POST request simulation in POSTMAN Rest Client
If you want to make good tests, the better solution is to write unit tests.
edited May 23 '17 at 12:33
Community♦
11 silver badge
11 silver badge
answered Jul 17 '16 at 9:17
mihkovmihkov
7517 silver badges28 bronze badges
7517 silver badges28 bronze badges
add a comment |
add a comment |
This is what I use to do:
Use a REST client tester like Postman or Fiddler. I use Postman which is an app for Google Chrome.
For easy construction of JSON you can create a HttpGet method on you controller and return a fake constructed ImageData
and call it from Postman. Here you will see the JSON and use that for input to the POST method.
public class ImageSaveController : ApiController
public ImageData Get()
return new ImageData
// insert test data here
;
[HttpPost]
public IHttpActionResult InsertImage(ImageData imageData)
System.Data.SqlClient.SqlConnection conn = null;
try
//Image save to database code here
catch (Exception ex)
return Content(HttpStatusCode.NotModified, ex.Message);
finally
if (conn != null)
conn.Close();
return Content(HttpStatusCode.OK,"");
add a comment |
This is what I use to do:
Use a REST client tester like Postman or Fiddler. I use Postman which is an app for Google Chrome.
For easy construction of JSON you can create a HttpGet method on you controller and return a fake constructed ImageData
and call it from Postman. Here you will see the JSON and use that for input to the POST method.
public class ImageSaveController : ApiController
public ImageData Get()
return new ImageData
// insert test data here
;
[HttpPost]
public IHttpActionResult InsertImage(ImageData imageData)
System.Data.SqlClient.SqlConnection conn = null;
try
//Image save to database code here
catch (Exception ex)
return Content(HttpStatusCode.NotModified, ex.Message);
finally
if (conn != null)
conn.Close();
return Content(HttpStatusCode.OK,"");
add a comment |
This is what I use to do:
Use a REST client tester like Postman or Fiddler. I use Postman which is an app for Google Chrome.
For easy construction of JSON you can create a HttpGet method on you controller and return a fake constructed ImageData
and call it from Postman. Here you will see the JSON and use that for input to the POST method.
public class ImageSaveController : ApiController
public ImageData Get()
return new ImageData
// insert test data here
;
[HttpPost]
public IHttpActionResult InsertImage(ImageData imageData)
System.Data.SqlClient.SqlConnection conn = null;
try
//Image save to database code here
catch (Exception ex)
return Content(HttpStatusCode.NotModified, ex.Message);
finally
if (conn != null)
conn.Close();
return Content(HttpStatusCode.OK,"");
This is what I use to do:
Use a REST client tester like Postman or Fiddler. I use Postman which is an app for Google Chrome.
For easy construction of JSON you can create a HttpGet method on you controller and return a fake constructed ImageData
and call it from Postman. Here you will see the JSON and use that for input to the POST method.
public class ImageSaveController : ApiController
public ImageData Get()
return new ImageData
// insert test data here
;
[HttpPost]
public IHttpActionResult InsertImage(ImageData imageData)
System.Data.SqlClient.SqlConnection conn = null;
try
//Image save to database code here
catch (Exception ex)
return Content(HttpStatusCode.NotModified, ex.Message);
finally
if (conn != null)
conn.Close();
return Content(HttpStatusCode.OK,"");
answered Jul 17 '16 at 9:18
MichaelMichael
1,1898 silver badges21 bronze badges
1,1898 silver badges21 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38418787%2fhow-to-test-a-web-api-post-method-which-receives-a-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown