1

the problem is as follows:

I want to consume a RESTful Service using get with a body. For testing purposes I am using Fiddler Web Debugger.

Now, the following GET request put into Fiddler gets me the result I am expecting:

GET http://localhost:3787/TerminologyService/Autosuggest/ HTTP/1.1
Host: localhost:3787
Content-Length: 215
Content-Type: application/json

{ 
"Text": "war",
"Count": "100",
"MedicationWeight": "7",
"ActivityWeight": "0",
"DiseaseWeight": "0",
"GeneWeight": "0",
"SymptomWeight": "0",
"AnatomyWeight": "0",
"OrderingType": "CATEGORY_DIVERSITY"
}

So now I'd do the same thing using $http.get. Here is what i have so far:

function getTerms(text, count, medWeight, actWeight, disWeight, genWeight, symWeight, anaWeight, orderingType)
    {
        var config = {
            headers: {'Content-Type' : 'application/json'},
            params: {Text : text,
                            Count : count,
                            MedicationWeight : medWeight,
                            ActivityWeight : actWeight,
                            DiseaseWeight : disWeight,
                            GeneWeight : genWeight,
                            SymptomWeight : symWeight,
                            AnatomyWeight : anaWeight,
                            OrderingType : orderingType}
        }

        return $http.get(
            'http://localhost:3787/TerminologyService/Autosuggest', config);
    }

This does get formed into a GET url:

http://localhost:3787/TerminologyService/Autosuggest?ActivityWeight=0&AnatomyWeight=0&Count=10&DiseaseWeight=0&GeneWeight=0&MedicationWeight=7&OrderingType=CATEGORY_DIVERSITY&SymptomWeight=0&Text=war

Unfortunately, this causes an error 500 at the webservice.

When I check the captured traffic in Fiddler thats been generated by the $http.get call I find that the JSON data is not being passed as the body (obviously, since it is passed in the URL). So I'm not able to get what I first tested in Fiddler

Any help is much appreciated

4
  • 500 means the error occurred on server side..you should debug code over server.. Commented Jan 6, 2016 at 19:46
  • Yes the error occurs because is the request is not formed as expected by the webservice. I'm not able to pass a GET body as I am in my Fiddler test. Commented Jan 6, 2016 at 19:57
  • Get request does pass all parameters through URL only.. Commented Jan 6, 2016 at 20:01
  • Looking at the GET request at the top of my OP in Fiddler shows that there is nothing appended to the URL and yet im getting the expected result. Commented Jan 6, 2016 at 20:22

2 Answers 2

1

Update:

Problem is solved by changing GET back to POST.

I had wrongly assumed that I was supposed to use GET

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

Comments

0

You should not be expecting a body in your GET requests on your backends, but for the sake of answering your question, as stated in $http docs you can pass a request's body message to config object's data property. So use data instead of params and it should have the behavior you desire.

1 Comment

Thanks very much for your response. I had assumed that I was supposed to use GET but that wasnt true. So I changed it back to Post in the backend and now it is working.

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.