ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am writing a C++ program that needs to contact the Stripe server
(https://stripe.com/documents/api#intro). It is a REST interface.
The development (and, for the moment, the deployment) platform is
Centos 6.6 and the program has to be compiled with the -m32 option
because it links with proprietary 32-bit libraries to which we do
not have the source.
Stripe provides APIs in Ruby, Python, PHP, and Java -- all interpreted
languages -- and also documents what it calls its "Curl" API, which
means, as I understand it, "here are the URLs, you connect to them
and send and retrieve data using any language you like". This could
literally be using the curl program in a shell script, or it could
be connecting to the URLs from within a program some other way.
Calling std::system for every Stripe transaction is, of course,
bogus. I am looking for a C++ class library that would enable me to
use the Stripe REST interface without forking a process (two
processes, actually) for each and every transaction. The other
alternative I thought of would be to keep a PHP interpreter running
at all times as a server, and connect to it using unix-domain (or even
Internet-domain) sockets, but I don't know if PHP can do that.
What C++ class library do you recommend for doing this? Search
engines have led me to Microsoft's Casablanca project, but I don't see
a CentOS package for it, and I couldn't build it from source on CentOS
using -m32. As always, thank you in advance for any and all replies.
et cetera. The point is, that curl does the post, then sends the post
data, then receives an OK response, followed by headers and (not shown
above) data. In other words, the program succeeds.
I have tried to accomplish the same within a C++ program, using
libcurl. This is, in pertinent part, what I have, which, according to
my reading of the fabulous manual, ought to work:
(I have not registered a callback function to receive the returned
data; for the moment, I am satisfied to let the returned data be
written to standard output, like the curl program does.)
It does not work. The curl utility outputs the retrieved data,
whereas my attempt to create the libcurl equivalent, produces a "Bad
Request" error message. Here it is in detail:
HTTP/1.1 400 Bad Request
Server: nginx
Date: Thu, 10 Mar 2016 02:35:47 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 522
Connection: keep-alive
(data then follow, containing a JSON representation of the error message)
It does not appear that the POST fields are being sent. What am I
missing? What does one do in libcurl that I have not done?
In case you were about to suggest it, I did run ltrace on the
successful curl program, and grep the output for curl_easy. The
output is not helpful, I see curl_easy_init() called with 5
arguments, rather than 0, and I see curl_easy_setopt() being called a
hundred times (this may be an exaggeration, but if so, it is only a
slight one) with 5 arguments rather than 3. But ltrace does not show
me the symbolic constants in the argument list to the curl_easy_*
functions, it does not show me their significance or how they were
computed, it does not tell me how to write my C++ program so that it
does what the curl program does.
As always, thank you in advance for any and all replies.
Indeed, it seems that the poster on the Stack Overflow site,
to whose question you directed me, was experiencing the
exact same problem I was, and that he solved it.
He does not, however, say how he solved it. He says,
"this was the option that solved my problem", words to
that effect -- and does not say what the option was.
If I knew how to contact that person, I would ask him
how he solved his problem, hoping that he remembers,
after 5 years. But as far as I can determine, Stack
Overflow gives me no way of contacting him. Unfortunately,
therefore, my question remains unanswered: thru use of
libcurl, I am successfully sending a POST request to
an HTTPS site, but it appears that the POST data are not
being sent. What am I doing wrong? As always, thank
you in advance for any and all replies.
What part of "Maybe give the libcurl request a user-agent?" did you miss?
From what you've already writen here, I can see that the curl request sent a user agent but the libcurl request did not.The comments on the stackoverflow post, which I specifically said to pay attention to, and which you failed to acknowledge at all, said that the POST request was not sent because the server said not to. Adding a user agent, therefore, would be the next reasonable step to try.
If that does not work, then you should set up a proxy such as Fiddler, Charles, mitmxproxy or zaproxy, use it to capture requests from both curl and libcurl, and then compare them to see how they are different. You would then determine why those differences are there and how to eliminate them.
And stop implying that you want private help via email. You want answers handed to you? Then you ask Stripe, not us, for support. Come to think of it, you should probably have just done that in the first place.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.