Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 822825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:51:12+00:00 2026-05-15T02:51:12+00:00

I have an API in NETMF C# that I am writing that includes a

  • 0

I have an API in NETMF C# that I am writing that includes a function to send an HTTP request. For those who are familiar with NETMF, this is a heavily modified version of the “webClient” example, which a simple application that demonstrates how to submit an HTTP request, and recive a response. In the sample, it simply prints the response and returns void,. In my version, however, I need it to return the HTTP response.

For some reason, Visual Studio reports that not all code paths return a value, even though, as far as I can tell, they do.

Here is my code…

  /// <summary>
  /// This is a modified webClient
  /// </summary>
  /// <param name="url"></param>
  private string httpRequest(string url)
  {
   // Create an HTTP Web request.
   HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;

   // Set request.KeepAlive to use a persistent connection. 
   request.KeepAlive = true;

   // Get a response from the server.
    WebResponse resp = request.GetResponse();

   // Get the network response stream to read the page data.
   if (resp != null)
   {
    Stream respStream = resp.GetResponseStream();
    string page = "";
    byte[] byteData = new byte[4096];
    char[] charData = new char[4096];
    int bytesRead = 0;
    Decoder UTF8decoder = System.Text.Encoding.UTF8.GetDecoder();
    int totalBytes = 0;

    // allow 5 seconds for reading the stream
    respStream.ReadTimeout = 5000;

    // If we know the content length, read exactly that amount of 
    // data; otherwise, read until there is nothing left to read.
    if (resp.ContentLength != -1)
    {
     for (int dataRem = (int)resp.ContentLength; dataRem > 0; )
     {
      Thread.Sleep(500);
      bytesRead = respStream.Read(byteData, 0, byteData.Length);

      if (bytesRead == 0)
       throw new Exception("Data laes than expected");

      dataRem -= bytesRead;

      // Convert from bytes to chars, and add to the page 
      // string.
      int byteUsed, charUsed;
      bool completed = false;
      totalBytes += bytesRead;
      UTF8decoder.Convert(byteData, 0, bytesRead, charData, 0,
       bytesRead, true, out byteUsed, out charUsed,
       out completed);
      page = page + new String(charData, 0, charUsed);
     }

     page = new String(System.Text.Encoding.UTF8.GetChars(byteData));
    }
    else
     throw new Exception("No content-Length reported");

    // Close the response stream.  For Keep-Alive streams, the 
    // stream will remain open and will be pushed into the unused 
    // stream list.
    resp.Close();
    return page;
   }
  }

Any ideas? Thanks…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:51:13+00:00Added an answer on May 15, 2026 at 2:51 am

    Clearly, if (resp == null) then you still need to return something…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this API that requires me to have a specific array key to
I have an API that is dependent on certain state information between requests. As
So Google Analytics does not have an API that we can use to get
So, I have an API that I need to implement in to an existing
I have a web API that returns python dictionaries or lists as a response
We have an API that will be only used by our new website for
We have restful api over HTTP. Amongst other clients we have also mobile-device clients
I have an API which sends an XML Request to a server: <?xml version=1.0
I have an API consisting of ASP.NET webservices callable through GET/POST/SOAP. A new functionality
I have an API call in my application where I am checking the time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.