Install Curl in Dev C++ [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
Hi I'm trying to install Curl : http://curl.haxx.se/download.html , Dev C++ and so far not achieved, could someone explain how to install Curl in Dev C++?

First copy ..\curl-7.40.0-devel-mingw64\include folder from downloaded package into C:\Dev-Cpp\MinGW64\include then copy libraries file (.o,.a,.lib) that are inside ..\curl-7.40.0-devel-mingw64\lib64 folder into C:\Dev-Cpp\MinGW64\lib then compile very first program , don't forget to link libcurl.a :
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
I am using Dev-c++ 5.11 (gcc 4.9.2) and curl-7.40.0-devel-mingw64.

Related

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

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to create a void that submit a form in this page: https://fs9.formsite.com/9jr4Rm/x1ncox1ipr/
how to do it?
void sendForm(char *answer)
{
//??
}
You can also do something like this: https://fs9.formsite.com/9jr4Rm/x1ncox1ipr/fill?1=hello
I don't want the program to open a site, just to send the data.
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.

libcurl implementation on public-private key authentication on SSH [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Created public and private key
ssh-keygen -t rsa <-- performed the operation in the SSH client
ssh-copy-id #
Note: no passphrase on the creation of the key
Can someone please help me on how to implement libcurl PutFile method using
- username
- private key
- public key
- sftp
Tried to browse on libcurl examples, but sadly this is the most similar example https://curl.haxx.se/libcurl/c/usercertinmem.html
Forget about usercertinmem.c, just take fileupload.c and add SSH options as needed.
Something like this:
curl_easy_setopt(curl, CURLOPT_URL, "sftp://username#host/path/file");
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_READDATA, fd);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_size);
curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PUBLICKEY);
curl_easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, pubkey_filename);
curl_easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, privkey_filename);
curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "");
curl_easy_setopt(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5, known_host_sign);
res = curl_easy_perform(curl);
You can read about these SSH-specific and other options in the options documentation.
Instead of CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 you can also use CURLOPT_SSH_KNOWNHOSTS or CURLOPT_SSH_KEYFUNCTION.

libcurl IMAP not working

Using the below code, I'm trying to get any of the libcurl IMAP commands to work.
Currently, regardless of the command set via CURLOPT_CUSTOMREQUEST, in my callback function the only data that is given is the oldest email (1st) in my inbox. I can even put something like "dfsafdasfasfaf" in the CURLOPT_CUSTOMREQUEST, and no error will be shown, and the oldest email will be printed from the callback.
I've tried using the sample codes on libcurl's site, to list folders, LSUB, etc and it's always the same - the only thing returned is the contents of the 1st email in my inbox.
I'm using curl 7.40 mingw32 on win32 g++ (-lcurldll).
Surely I must be doing something wrong. If you could take a moment to correct my error, I would be most appreciative. Thank you.
EDIT - Even if you don't know the answer, could you please leave a comment if you have successfully gotten libcurl IMAP to work before? Because if no one has gotten libcurl imap to work before I'll stop wasting my time with it and move on to VMime or another option..
EDIT2- My principal question is how can I list folders via libcurl?
size_t writeCallback(char* buf, size_t size, size_t nmemb, void* up)
{
printf("%s\n", buf);
return size*nmemb; //tell curl how many bytes we handled
}
int main(void)
{
CURL *curl;
CURLcode res = CURLE_OK;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_USERNAME, "gmailuser");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "password");
curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.gmail.com/INBOX");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "LIST");
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);
}
_getch ();
return (int)res;
}
In order to get list of folders in a given GMail inbox, you should use:
curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.gmail.com/");
Also, I believe you don't need this line to perform LIST request:
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "LIST");
I have tested it on Linux, on libcurl version 7.35.0, though I believe the problems you are encountering are not OS-specific and are rather caused by the current state of the implementation of IMAP support in the library. You can find source code for libcurl version 7.35.0 here.
You can also find more examples of current libcurl IMAP support on the examples page (see the links on the right for more detailed examples).

Get the HTML of a site [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to get into a string (or a char[]) the html of a page...( and such)
I know how to use basic sockets, and connect as a client/server...
I've wrote a client in the past, that gets an ip & port, and connects to it, and send images and such using sockets betwen the client & the server...
I've searched the internet a bit, and found I can connect to the website, and send a GET request, to get the HTTP content of a page and store it in a variable, though I have a few problems :
1) I'm trying to get the HTML of a page that isnt the main page of a site, like, not stackoverflow.com, but stackoverflow.com/help and such (not the "official page of the site", but something inside that site)
2) I'm not sure how to either send or store the data I got from the GET request...
I saw there are outside libraries I could use, but I rather use sockets only...
By the way - I'm using Windows 7, and I aim that it'll work on Windows only(so it's fine if it wont work for Linux)
Thanks for you'r help! :)
To access a resource on some host you just specify the path to the resource in the first line of the request, just after the 'GET'. E.g. check http://www.jmarshall.com/easy/http/#http1.1
GET /path/file.html HTTP/1.1
Host: www.host1.com:80
[blank line here]
I'd also recomend using some portable library like Boost.ASIO instead of sockets. But I'd strongly recomend you to use some existing, portable library implementing HTTP protocol. Of course only if it is not a matter of learning how to implement it.
Even if you want to implement it by yourself it'd be worth knowing the existing solutions. For instance this is how you can get a webpage using cpp-netlib (http://cpp-netlib.org/0.10.1/index.html):
using namespace boost::network;
using namespace boost::network::http;
client::request request_("http://127.0.0.1:8000/");
request_ << header("Connection", "close");
client client_;
client::response response_ = client_.get(request_);
std::string body_ = body(response_);
This is how you can do it using cURL library (http://curl.haxx.se/libcurl/c/simple.html):
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
Both libraries are portable but if you'd like to use some Windows-specific API you might check WinINet (http://msdn.microsoft.com/en-us/library/windows/desktop/aa383630%28v=vs.85%29.aspx) but it's less pleasant to use.

Curl simple https request returns nothing C++

I'm using Visual Studio C++ 2010 and it's working just fine with cURL but the problem is that https requests returns nothing. instead of showing the output:
#include "StdAfx.h"
#include <stdio.h>
#include <curl/curl.h>
#include <conio.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.com");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
_getch();
return 0;
}
This code for example, it's just a https request to Google, but it returns nothing just because it starts with https. and if I take away the "s" of https, it works just fine: "http://www.google.com.br" shows the result normally. what am I missing here? I'm using the example from the cURL.
I tried with other websites and same thing happened. :/ like https://www.facebook.com
Btw also if you guys know how do I store the webpage content in a string, I would be glad to know.
Thanks in advance. :)
This simple example works for me:
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.co.uk");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
I got the source code and built the library long time ago but I'm sure I enabled the SSL support before compiling the sources. Make sure you have OpenSSL installed and (in case you're working under Linux) you have the PKG_CONFIG_PATH variable initialized properly. These are two options you specify when executing the configure script.
--with-ssl=PATH Where to look for OpenSSL, PATH points to the SSL
installation (default: /usr/local/ssl); when
possible, set the PKG_CONFIG_PATH environment
variable instead of using this option
--without-ssl disable OpenSSL
I hope it helps.
If you're using Windows, this post can be also useful for you:
Building libcurl with SSL support on Windows