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 6351889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:05:43+00:00 2026-05-24T22:05:43+00:00

I am currently working on integrating a prototype product I made into a larger

  • 0

I am currently working on integrating a prototype product I made into a larger program. What I did in the prototype was create a HTTP server on a microcontroller, and then wrote some HTML to call .cgi functions on the web-server. This was so I could control I/O on the micro controller via an ethernet.

My html seems very straight forward, to call a cgi function on the microcontroller I have made buttons with the following syntax:

<script type="text/javascript">
function my_confirm(a){
  var r=confirm("Are you sure you'd like to run "+a+"?");
  if (r==true)  
    location.href = a;
}
</script>
<button type = "button" onclick=" my_confirm('started.cgi')" >Started</button>

additionally, if i were to type in “169.254.129.12/started.cgi” into a web browser, the microcontroller would respond appropriately. Now that the prototype is completed ahead of schedule, my new task is to integrate my controls into a C++/CLI program. GREAT. I have never written in C++…

Rather than re-doing all of the backend stuff, I would like to add a menu to send similiar requests. Over the last 4-5 days I have gotten a menu in VS2005 and have had limited success, with the code below:

int sendHttpRequestAndRespond(System::Uri^ url){
    if(url->Scheme == System::Uri::UriSchemeHttp){
        HttpWebRequest^ request = dynamic_cast<HttpWebRequest^>(WebRequest::Create(url));
        request->Method = System::Net::WebRequestMethods::Http::Get;
        return 0;
    }
    //HttpWebResponse^ response = dynamic_cast<HttpWebResponse^> (request->GetResponse());
    //RequestState^ state = gcnew RequestState();
    //state->request = request;
    //try{
    //  IAsyncResult^ response = dynamic_cast<IAsyncResult^> (request->BeginGetResponse(gcnew AsyncCallback( responseReceived),state));
    //}
    //catch(WebException^ e){}
    else
        return -1;
}

With the code written as shown above(with comments present) the I/O control of the microcontroller does not operate properly. Oddly, if I put in the HttpWebResponse line, things (sometimes) go properly, and other times, nothing seems to happen. Lastly, if I use the AsyncResponse, things are similiar to if I use the HttpWebResponse portion.

Now my thought/understanding was that merely putting in the request via the GET method I am using in the code shown above would initiate the I/O control on the microcontroller, but it seems the response plays a role in it as well.

Do any of you have a better route to go with this? At this point I am highly confused/frustrated and open to any advice! Thank you,

EDIT 1: UPDATED CODE:

int sendHttpRequestAndRespond(System::Uri^ url){
    if(url->Scheme == System::Uri::UriSchemeHttp){
        HttpWebRequest^ request = dynamic_cast<HttpWebRequest^>(WebRequest::Create(url));
        request->Method = System::Net::WebRequestMethods::Http::Get;
        RequestState^ state = gcnew RequestState();
        state->request = request;
        try{
                IAsyncResult^ response = dynamic_cast<IAsyncResult^> (request->BeginGetResponse(gcnew AsyncCallback( responseReceived),state));
            }
        catch(WebException^ e){}
        return 0;
    }

With this code I get into my callback function (responseReceived) the first two times I call the function, but never on the 3rd or further time. I am testing this with http://www.facebook.com, as this seems to work for my CGI calling, but only the first two times as well.
Thanks,

EDIT 2: Resolution and new problems!
Okay, I figured out my problem was due mostly to not ending the requests. In the callBack function I wasn’t ending the request, and HTTP protocol has a 2 connections/ip restriction, making the first two calls work, but future ones wouldn’t.

Now my new issue is that on the asyc call I a using, it first does synchronous DNS resolution. Since I am sending these commands to an embedded computer with an IP, there’s no DNS inbetween, and the function blocks for a long time. Once my computer realizes there’s been a DNS resolution error, it fires off the request any ways, and it works! Subsequent requests work instantly, as there’s a cache that remembers the failure.

So im about 99% of the way there, but I need to fix this first time lockup some how. My current ideas are:

Somehow disable dns resolution before the request

Shorten the dns resolution timeout from 60+ seconds to 1ish seconds

trick my comptuer/the computer the program runs on into thinking that http://169.254.129.12 has an ip address of 169.254.129.12 (local host file??)

I am not sure how to accomplish those, or if there are better ideas??

Thank you,

Any better ideas?

  • 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-24T22:05:44+00:00Added an answer on May 24, 2026 at 10:05 pm

    I’m not very familiar with the HttpWebRequest class and related classes, but as I understand it the request doesn’t get sent to the server until you either (a) send it explictly by writing to the request stream, or (b) retrieve the response by calling GetResponse. So for starters I think you need to uncomment all that stuff.

    I wonder why you return on line 5 before doing anything with the request. I know this code is a work in progress. But surely you don’t want to return before doing anything?

    And finally, you’re using async comms, which is probably extra complexity that you can do without right now. I suggest you do everything synchronously first to get it working, and then switch to async if you really need to.

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

Sidebar

Related Questions

Working on integrating the like button into a site. The site is currently running
I am currently working on integrating a PHP/MySQL-based e-commerce website I manage with the
I'm currently working on integrating the TFS source control system at my work ...
I'm working on integrating Ben Gottlieb's Twitter-OAuth-iPhone code into my cocos2d 0.99.5 project using
I am currently working to integrate rcov with our Hudson server. I am able
Im currently looking into the difference between IBM Websphere Application Server and IBM Websphere
I'm currently integrating springs-security into our new web application stack. We will need to
Im working on integrating db4o into my project and I have some questions. I
I'm currently working on what I would call integration tests. I want to verify
Currently working in the deployment of an OFBiz based ERP, we've come to the

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.