Skip to content

Instantly share code, notes, and snippets.

@kenny-evitt
Created November 26, 2018 15:30
Show Gist options
  • Select an option

  • Save kenny-evitt/9c55302121127f7f9b015f9482a95716 to your computer and use it in GitHub Desktop.

Select an option

Save kenny-evitt/9c55302121127f7f9b015f9482a95716 to your computer and use it in GitHub Desktop.

Revisions

  1. kenny-evitt created this gist Nov 26, 2018.
    38 changes: 38 additions & 0 deletions HttpWebRequest example (fragment).linq
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@

    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\"}";
    }