Posts

Showing posts from April, 2018

How to call/Consume post API with Header in C#

This is simple sample code written to consume post API which has header   Here I am using newtonsoft dll to convert class into json     //using Newtonsoft.Json     private void PostWithHeader()     {         WebRequest req = null ;         WebResponse rsp = null ;         string url = "http://" ; // Pass url here         string API_Response = "" ;         jsonParameter P = new jsonParameter () { userid=1};         try         {             req = WebRequest .Create(url);             //Uncomment below line if Post with Basic auth also ...

Multipart/form-data using basic auth

// Implements multipart/form-data POST in C# http://www.ietf.org/rfc/rfc2388.txt // http://www.briangrinstead.com/blog/multipart-form-post-in-c public static class FormUpload {     private static readonly Encoding encoding = Encoding.UTF8;     public static HttpWebResponse MultipartFormDataPost(string postUrl, string userAgent, Dictionary<string, object> postParameters)     {         string formDataBoundary = String.Format("----------{0:N}", Guid.NewGuid());         string contentType = "multipart/form-data; boundary=" + formDataBoundary;         byte[] formData = GetMultipartFormData(postParameters, formDataBoundary);         return PostForm(postUrl, userAgent, contentType, formData);     }     private static HttpWebResponse PostForm(string postUrl, string userAgent, string contentType, byte[] formData)     { ...