private async Task <string> CallApi1(string method, object dObj) { var json = "{\"session\":\"sci4ejgpsoqr7m2bt6fchgbk41\",\"module_name\":\"Users\",\"query\":\"\",\"order_by\":\"\",\"offset\":0,\"select_fields\":[\"id\",\"user_name\",\"staff_id_c\",\"user_group_c\",\"last_login_date_c\",\"email1\",\"date_entered\",\"date_modified\",\"status\"],\"link_name_to_fields_array\":[[\"Key\":\"name\",\"Value\":\"email_addresses\"],[\"Key\":\"value\",\"Value\":[\"id\",\"email_address\"]]],\"max_results\":10,\"deleted\":false,\"favorites\":false}"; var values = new Dictionary <string, string> { { "method", method }, { "input_type", "JSON" }, { "response_type", "JSON" }, { "rest_data", json }, }; var client = new System.Net.Http.HttpClient(); var content = new SuiteAPI.MyFormUrlEncodedContent(values); try { var response = await client.PostAsync(apiUrl, content).ConfigureAwait(false); var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false); return(responseString); } catch (Exception ex) { throw new Exception("Error handling result." + ex.ToString()); } return(null); }
private async Task <string> CallApi(string method, object dObj) { var json = JsonConvert.SerializeObject(dObj); var values = new Dictionary <string, string> { { "method", method }, { "input_type", "JSON" }, { "response_type", "JSON" }, { "rest_data", json }, }; var client = new System.Net.Http.HttpClient(); var content = new SuiteAPI.MyFormUrlEncodedContent(values); try { var response = await client.PostAsync(apiUrl, content).ConfigureAwait(false); var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false); return(responseString); } catch (Exception ex) { throw new Exception("Error handling result." + ex.ToString()); } return(null); }
private static byte[] GetContentByteArray(IEnumerable <KeyValuePair <string, string> > nameValueCollection) { if (nameValueCollection == null) { throw new ArgumentNullException("nameValueCollection"); } StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair <string, string> current in nameValueCollection) { if (stringBuilder.Length > 0) { stringBuilder.Append('&'); } stringBuilder.Append(MyFormUrlEncodedContent.Encode(current.Key)); stringBuilder.Append('='); stringBuilder.Append(MyFormUrlEncodedContent.Encode(current.Value)); } return(Encoding.Default.GetBytes(stringBuilder.ToString())); }
public MyFormUrlEncodedContent(IEnumerable <KeyValuePair <string, string> > nameValueCollection) : base(MyFormUrlEncodedContent.GetContentByteArray(nameValueCollection)) { base.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); }