-1

UPDATE

I have looked through many articles about how to post json data, but I also got error, so I want to know how to organize the POST data like python implementation.


I got a demo using Python language, there is a Post method with some data :

data = {
    "token": token,
    "voice_samples": [
        {"wave": string1},
        {"wave": string2},
        {"wave": string3}
    ]
}

response = requests.post(endpoint, json=data)

I want to perform a same Post method using Objective-C with AFNetworking or C# , but I got different errors using many ways to organize data , can someone give me an example to send a Post method with the same data format described above ?

It seems very easy , but I always got error.

yifan_z
  • 256
  • 1
  • 10
  • So you want to post JSON data? see: https://stackoverflow.com/questions/34434728/how-to-post-json-parameters-using-afnetworking. Also possible in .NET, but you'll have to mention which framework you want to use. – Greg Oct 09 '17 at 12:11

1 Answers1

0

Here is a suggestion how it works with C#.

First install NuGet-Package Microsoft.AspNet.WebApi.Client:

Install-Package Microsoft.AspNet.WebApi.Client

using System.Net.Http;
//...
var loToken = new
{
    token = "token",
    voice_samples = new List<dynamic>()
    {
        new {wave = "string1"},
        new {wave = "string2"},
        new {wave = "string3"}
    }
};

var loClient = new HttpClient() { BaseAddress = new Uri(endpoint) };
var loResp = await loClient.PostAsJsonAsync("", loToken);
Console.WriteLine(loResp.StatusCode.ToString());
PinBack
  • 2,499
  • 12
  • 16