Instantly share code, notes, and snippets.

@bderose /Dnaas.cs
Last active Jul 11, 2018

Embed
What would you like to do?
Example DNaaS API calls and workflow in C#
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;
class Dnaas {
private static readonly HttpClient client = new HttpClient {
BaseAddress = new Uri("http://automation.berkeley.edu/dex-net-api/"),
};
static void Main(string[] args) {
var jsonParams = JsonConvert.SerializeObject(new {
metric = "robust_ferrari_canny",
gripper = new {
fingertip_x = 0.01,
fingertip_y = 0.01,
gripper_offset = 0.01,
palm_depth = 0.05,
width = 0.08
}
});
var jsonContent = new StringContent(jsonParams, Encoding.UTF8, "application/json");
var meshContent = new ByteArrayContent(File.ReadAllBytes("/path/to/your/mesh.obj"));
var form = new MultipartFormDataContent();
form.Add(meshContent, "file", "file");
form.Add(jsonContent, "params", "params");
var response = client.PostAsync("upload-mesh", form)
.GetAwaiter()
.GetResult();
response.EnsureSuccessStatusCode();
var result = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment