0

I must implement method in my application which will send some data (which according to api documentation should be JSON) using GET method (it is weird...). How I can do this using c sharp in windows 8 (RestSharp lib is not working there). I don't have any experience in REST clients but I have already implement other features but there data was sended by POST or DELETE methods. I have tried "tranlate" json to get like this: JSON:

{
a = "foo",
b = "bar
}

GET URL:

__SITE__?a=foo&b=bar

But server return null values (not error). I don't know how to deal with this thing :/ Thanks for help in advance :)

Krzysztof Kaczor
  • 5,408
  • 7
  • 39
  • 47

3 Answers3

0

If you have api you have name of param that you should send. Just convert the data into json and sind is as this param. If you have to send json why you`re sending param a and b as 2 diffrent strings ?

remember that a GET method can be invoked by HttpClient. Just invoke the URL

Fixus
  • 4,631
  • 10
  • 38
  • 67
  • ok but how should be that parameters named (one that with json)? json? :D – Krzysztof Kaczor Sep 14 '12 at 14:14
  • `which according to api documentation should be JSON` How can I know what is in your API ? If you`re using application with API you should have there the name of param. If it`s your application (webservice) you should know it – Fixus Sep 14 '12 at 14:21
  • In documentation there is no information about it. I'm asking about general way how to do this. I have got only info how to use curl curl -v -H 'Token: 124asdasd254' \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ -d '{a: "foo", b: "bar"}' \ -X GET \ _SITEURL_ – Krzysztof Kaczor Sep 14 '12 at 15:23
0

Finally it turned out (in my case) that API also accepts providing data in that way: URL?a=foo&b=bar regardless of the fact that it should be json.

Krzysztof Kaczor
  • 5,408
  • 7
  • 39
  • 47
-1

Long story short, I think this will be most illuminating .. it "fills in the blanks" with using HttpClient to fire JSON Formatted data at a REST API

How do you set the Content-Type header for an HttpClient request?

Community
  • 1
  • 1
Chris
  • 11
  • 1
  • Chris it is helpful if you summarize the key points from the article you are linking too in your answer. It will make it easier for the OP and other users to determine if the answer is correct. – Scott Sep 19 '12 at 09:07