This sample code template shows a json request to the Shipment Server using C#.
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string URL = "https://www.shipmentserver.com/ship/ShipmentServerModule.dll"; var values = new Dictionary<string, string> { { "actor", "get from consignor" }, { "key", "get from consignor" }, { "options", "{depending on the method https://consignor.zendesk.com/hc/en-us/articles/360001457853-Overview-of-methods-for-Consignor-Shipment-Server-API}" }, { "command", "method from https://consignor.zendesk.com/hc/en-us/articles/360001457853-Overview-of-methods-for-Consignor-Shipment-Server-API" }, { "data", "{https://consignor.zendesk.com/hc/en-us/articles/360003127694-Implementation-and-request-examples}" } }; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(URL); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var content = new FormUrlEncodedContent(values); HttpResponseMessage response = client.PostAsync(URL, content).Result; Stream received = response.Content.ReadAsStreamAsync().Result; StreamReader readStream = new StreamReader(received, Encoding.UTF8); string jsonString = readStream.ReadToEnd(); if (response.IsSuccessStatusCode) { Console.WriteLine("{0}", jsonString); } Console.ReadLine(); client.Dispose(); } } }
You may use an editor like Notepad++ to edit and test requests. There's a plugin available that makes it easy to use. Notepad++ can be downloaded for free.
Here is how you install the plugin:
- Open Notepad++ > Plugins > Plugin manager and select CS-Script (C# intellisense). Click Install. You may need to restart Notepad++ for the installation to finish.
- Now you should see the CS-Scrip plugin in the Plugins tab.
- Make your code example and save as a .cs file.
- You should now be able to use Build (validate), Run, Debug or Debug External Process. If your code is invalid, you can only work with debugging. Example below shows a code example and the server response.