1

I would like to make a small script that will retrieve a result in JSON. For that I will use C# and Flurl however I am blocked on a little step:/

As for the parameters (username & password) I have already tried with postman and it works. Now I'm trying to make my first connection with C#:)

using System.Threading.Tasks;
using Flurl.Http;

namespace Script
    {
        class Program
        {
            static async Task Main(string[] args)
            {
                var result = await "https://ip/api/Login.json".PostUrlEncodedAsync(new
                {
                    name = "login",
                    pwd = "password"
                });
            }
        }
    }

And I have an a problem with PostUrlEncodedAsync.

Message:
Message

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Digitag
  • 235
  • 3
  • 5
  • 11
  • Don't you think it has something to do with your url/endpoint _"https://ip/api/Login.json"_ It ends with **.json** – Oswald Umeh Dec 10 '18 at 15:59
  • Hello, no we need to use this url to connect on the device and after that you can create your first GET :) On Postman he works correctly. – Digitag Dec 10 '18 at 16:03
  • What is the result of the call above? – Todd Menier Dec 10 '18 at 18:13
  • Hi @ToddMenier I update my post with an img :) – Digitag Dec 11 '18 at 10:18
  • I may have forgotten an element of Flurl ? – Digitag Dec 11 '18 at 10:53
  • @Digitag Yes, it looks like you have installed the package Flurl.Http, but not Flurl itself, or perhaps you have some binding redirects. Can you check if you have the Flurl package installed in your app, and what version it is? – mason Dec 13 '18 at 14:40
  • Your question text says you want to retrieve some JSON. But all you're doing is posting a form. You need to add a .ReceiveJson extension method to the end of your chain. – mason Dec 13 '18 at 14:43
  • @mason No the objectif is to create a POST json with flurl. you can see this [link](https://stackoverflow.com/questions/53778304/post-json-with-flurl) – Digitag Dec 14 '18 at 13:54
  • @Digitag You are confusing things a lot. You say you want to retrieve JSON, yet you don't call the right extension methods to do that. Your new question says you want to send some JSON, yet you're not using the right extension methods to do that. You need to clearly define what it is you're trying to do, look at the Flurl documentation, and try to do that. – mason Dec 14 '18 at 13:59

1 Answers1

1

It looks like the problem is with your project references.

Please have a look at your project references for Flurl.dll. If you can't see Flurl there then please apply following command in your package manager window:

PM> Install-Package Flurl -Version 2.8.0

If you can see Flurl there, please try to reinstall your nuget package by following command in your package manager window:

PM> Update-Package -Id Flurl –reinstall

Hope this helps.

Ayberk
  • 536
  • 2
  • 12
  • Hi @Ayberk Thank you for your comment this problem is now solved! :) However the format of parameters in json how can we put this element? ` { "aaaUser" : { "attributes" : { "name" : "apic:domaine\\login", "pwd" : "123456" } } }` – Digitag Dec 13 '18 at 14:54
  • @Digitag You'd need to make a new question if you can't figure that out. – mason Dec 13 '18 at 14:58
  • Ha ok tahnks. I am sorry :) How can I close this case ? – Digitag Dec 13 '18 at 15:01