adding RestSharp?

JHDevJHDev USMember ✭✭

Hi. I am only successful in adding RestSharp to Xamarin.iOS or Xamarin.Droid.

However, I would like to add the package to the non-platform specific folder.
I am getting this error

Could not install package 'RestSharp 105.2.3'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

it seems like I cannot add it.

So if I can only add restsharp to each platform, how can I write the network code just once. For example make a network fetch class under non-platform specific folder which calls all the restsharp stuff. and then I can call from .iOS and .Droid side?

What about all the restsharp.portable packages that I see??

Answers

  • QuakeulfQuakeulf NOMember ✭✭✭
    edited March 29

    We've made use of System.Net.Http for a Forms.Portable cross-platform project, and it does all the stuff RestSharp does that we needed but with a slightly different syntax. You could try that if RestSharp is giving you issues.

  • JHDevJHDev USMember ✭✭

    @Quakeulf said:
    We've made use of System.Net.Http for a Forms.Portable cross-platform project, and it does all the stuff RestSharp does that we needed but with a slightly different syntax. You could try that if RestSharp is giving you issues.

    Are you using httpWebRequest or httpClient?

    I found the httpWebRequest - alot of trouble to use. Things like content-length does not exist. I tried to modify the header like content length via Key/Value and it will not let me! They changed the calls recently (?? at least the version of .NET in Xamarin I have) to
    GetRequestStreamAsync() and GetResponseAsync() and it was VERY difficult to find example to use the Async version of the code. It works in the end passing the result to JSON.net (I love JSON.net) but I was hoping something like RestSharp is more higher level.

    Still alot better than having to write Java and ObjC code separately each platform! So that's 100% my goal to write this code just once.

    Now I downloaded a package called PortableRest.

  • QuakeulfQuakeulf NOMember ✭✭✭

    HttpClient with NewtonSoft's.

  • DavidClarkeDavidClarke NZBeta, University ✭✭

    @JHDev said:

    Now I downloaded a package called PortableRest.

    How have you found PortableRest in practice - are you still using it? Any issues?

  • JHDevJHDev USMember ✭✭

    @DavidClarke said:

    @JHDev said:

    Now I downloaded a package called PortableRest.

    How have you found PortableRest in practice - are you still using it? Any issues?

    Yes, I am still using it. It's relatively trouble free, only a couple small issues I came across that could be resolved through research, and it has been working on both iOS and Android..
    much better than the alternative of writing your own URL session and JSON parsing routine.

Sign In or Register to comment.