This project contains code for executing POST methods. PUT should be analogous: Qlik Branch
It uses the method WebClient.UploadString Method (System.Net) to do the post. There is an overload for that method that I believe can be used to do a PUT instead.
For serialization and deserialization of JSON I would recommend going with some standard library. Here is one example: Deserialize an Object
Hi Øystein Kolsrud Thanks for replying.
I went through the project you have attached.
I am using HttpWebRequests and I am trying to fire a PUT request with a JSON body that is required for updating the information of a user. Whenever I am doing a PUT request. I am seeing two errors on it. The error and the exceptions are as follow:
1.) A GET request has to be made in order to make a PUT request(as the resolution I applied a GET method before the PUT method and I used the same HttpWebRequest object to modify the call as PUT but that is getting stuck on an exception that says “System.InvalidOperationException” )
2.) System.InvalidOperationException is not letting me add a request body with a PUT request.
3.) Parameters being provided with the requests are Method, Accept(Content-Type), Headers(Xrfkey), client issued certificate, X-Qlik-User(userDirectory and userId), writing the request stream with stream.write(jsonData, 0, jsonData.Length)
Any quick suggestion w.r.t will be appreciated.
I'm no expert on the HttpWebRequest class, but I think you need to be careful when reusing the same request object multiple times. There are some caveats there:
I personally find the WebClient class to be easier to work with as it provides some useful abstractions on top of the requests that fit well with for instance Qliks REST APIs.
Your observation on having to do a "GET" before doing a "PUT" is correct though. When you do the first Get, you will get a cookie from Qlik that is used for authentication, and that cookie needs to be included in any following non-get operations. I actually had that flow automated in that project I linked to, but realized that I never pushed my fix. Thanks for pointing that out!