Skip to content

Instantly share code, notes, and snippets.

@kenny-evitt
Created November 26, 2018 15:30
Show Gist options
  • Save kenny-evitt/9c55302121127f7f9b015f9482a95716 to your computer and use it in GitHub Desktop.
Save kenny-evitt/9c55302121127f7f9b015f9482a95716 to your computer and use it in GitHub Desktop.
C# web request example
bool CallGenerateImageOfFirstPageWebMethod(int documentLocationId)
{
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(
String.Format(
"http://snyiis1/Apps/documents/{0}/generate-preview-image",
documentLocationId));
request.Method = "POST";
request.ContentLength = 0;
HttpWebResponse response = null;
string responseContent = null;
try
{
response = (HttpWebResponse)request.GetResponse();
using (StreamReader responseStreamReader = new StreamReader(response.GetResponseStream()))
{
responseContent = responseStreamReader.ReadToEnd();
}
}
catch (Exception ex)
{
ex.Dump();
response.Dump();
responseContent.Dump();
return false;
}
return
response != null
&& response.StatusCode == HttpStatusCode.OK
&& responseContent == "{\"status\":\"true\"}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment