[Solved] How to submit a from in this page c++ [closed]


I’m not exactly sure what you’re planning to achieve, but here’s my guess:
Your easiest solution is to use libcurl (available on various OSes):
Documentation is here: https://curl.haxx.se/libcurl/c/
Or, if you prefer examples (I do) here’s a simple example to post some stuff on a remote server using http:
https://curl.haxx.se/libcurl/c/http-post.html

If you want to use GET (like the ?1=hello parameter), you can try the same without the CURLOPT_POSTFIELDS line. Just use:

curl_easy_setopt(curl, CURLOPT_URL, “https://fs9.formsite.com/9jr4Rm/x1ncox1ipr/fill?1=hello“);

If you can’t (or don’t want to) use curl, you can implement HTTP over a simple socket connection. I’ve done that on an arduino, no problem. Connect to fs9.formsite.com’s TCP port 80 (it’s the default), send:

GET /9jr4Rm/x1ncox1ipr/fill?1=hello HTTP/1.1\r\n
Host: fs9.formsite.com\r\n
Connection: close\r\n
\r\n

(where \r\n is a DOS-style line ending, but most of the time \n works fine)

You could tell us more about the system you’d like this to run on for better responses (e.g. OS, maybe compiler name would be nice).

Edit: I’ve modified the above curl example. Here it is:

#include <stdio.h>
#include <curl/curl.h>

CURL *curl;
CURLcode res;

void sendForm(const char *answer)
{
  curl = curl_easy_init();
  if(curl)
  {
    curl_easy_setopt(curl, CURLOPT_URL, answer);

    res = curl_easy_perform(curl);
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
    curl_easy_cleanup(curl);
  }
  else
  {
    fprintf(stderr, "curl is NULL\n");
  }
}

int main(void)
{
  curl_global_init(CURL_GLOBAL_ALL);
  sendForm("https://fs9.formsite.com/9jr4Rm/x1ncox1ipr/fill?1=hello");
  curl_global_cleanup();
  return 0;
}

Then you can compile it with whatever you use. I use gcc on Linux:

gcc curltest.c -l curl -o curltest

Then run:

./curltest

Just one more suggestion: don’t use void for this return type. Network connection should always be considered unreliable, and returning a success/error code is nice.

solved How to submit a from in this page c++ [closed]