0

I need help.

I have a method: PostCustomer

HttpResponseMessage PostCustomer([FromBody] CustomerRec Logs, [FromBody] Customer customer)

Now my problem is how will I able to test this through fiddler

I know I need to call for example:

"//api/customer/PostCustomer"
  • But how will I pass parameters on this?
  • I'm testing this using fiddler.
3
  • Might I suggest the chrome plugin postman - fantastic tool for API testing. Also have you seen this post: stackoverflow.com/questions/10215170/… Commented Nov 13, 2014 at 7:02
  • I also use that for testing. But what I want to see is on how to test this on fiddler particularly. Commented Nov 13, 2014 at 7:17
  • do you mean telerik Fiddler Web Debugger?? Commented Nov 13, 2014 at 7:39

1 Answer 1

2

I'm not sure if you are asking how to build the url request (passing the parameters for your method through url)

If that's it, it should be like this

api/customer/PostCustomer/?FirstParameter=Example&SecondParemeter=Example2

If you mean the request itself

string postData = string.Format("?FirstParameter=" + txt_First.Text + "&SecondParemeter=" + txt_Last.Text);
        byte[] data = Encoding.UTF8.GetBytes(postData);
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("..../api/customer/PostCustomer"/" + postData);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Accept = "application/json";
        request.ContentLength = data.Length;

        using (Stream requestStream = request.GetRequestStream())
        {
            requestStream.Write(data, 0, data.Length);

        }

        try
        {
            using (WebResponse response = request.GetResponse())
            {
                var responseValue = string.Empty;


                // grab the response  
                using (var responseStream = response.GetResponseStream())
                {
                    using (var reader = new StreamReader(responseStream))
                    {
                        responseValue = reader.ReadToEnd(); // read the full response

                    }
                }
                if (responseValue != "")
                {
                    //Do something here if response is not empty

                }
            }
        }
        catch (WebException ex)
        {
            // Handle error
        }

PS: Can't comment on post because it asks for 50+ reputation...

Sign up to request clarification or add additional context in comments.

2 Comments

I'm actually passing two objects as parameters
Ah Sorry I didn't understood that. Have you tried serializing the object and send the variable with the serialized object inside?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.