Join the Stack Overflow Community
Stack Overflow is a community of 6.2 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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

share|improve this question
    
500 means the error occurred on server side..you should debug code over server.. – Pankaj Parkar Jan 6 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. – Fabian L Jan 6 at 19:57
    
Get request does pass all parameters through URL only.. – Pankaj Parkar Jan 6 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. – Fabian L Jan 6 at 20:22
up vote 1 down vote accepted

Update:

Problem is solved by changing GET back to POST.

I had wrongly assumed that I was supposed to use GET

share|improve this answer

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.

share|improve this answer
    
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. – Fabian L Jan 6 at 20:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.