I'm trying to use libcurl to do a SOAP http post to a web service. I have the SOAP requests already formed in XML files which I generate. Now I need to transefer these XML files to the webservice. N.B. I'm pretty new to writing webservices (especially in C).
Is there a way do send the SOAP requests straight from the XML file using libcurl? Or do I have to read the contents into a string? I'm restricted to using the C programming language to complete the task.
I've been looking through documentation and different code snippets but I can't seem to locate anything to do the requested. This curl link does it through a string http://curl.haxx.se/libcurl/c/post-callback.html). FOr speed purposes I would greatly prefer to not have to pass to a string before sending it.
you use curl_easy_setopt()? then you may want to take a look at CURLOP_WRITEFUNCTION and CURLOPT_WRITEDATA.
The way I do this:
* Get TinyXML, load the file into a TiXmlDocument and use the TiXmlPrinter to get the XML file as string
* Set the value of the string in the body of the post request( also, set headers, but they are the same as HTTP standard headers)
* Take a look at curl_easy_setopt() for callback and other stuff (:
Good Luck (:
Related
I am a freelancing author and have gathered tons of hours of interview material which needs to be transcribed.
While browsing the Internet I came across IBM Watson "Speech to text" which should be the ideal solution to handle that huge amount of spoken word.
After registration I am struggling with even opening it. Since I am not very much equipped with programming, etc.
Can someone provide an example with steps that I can follow to achieve my task?
which platform you want to use Speech to text service on it ?
If you are not a coder, then the best starting point for you will be Node-RED. Take a look at this tutorial that creates a translator - https://developer.ibm.com/tutorials/build-universal-translator-nodered-watson-ai-services/?cm_mmc=IBMDev--Digest--ENews2019-_-email&spMailingID=39408813&spUserID=MzYzODEwODAwNzk4S0&spJobID=1500992192&spReportId=MTUwMDk5MjE5MgS2
If uses Speech to Text, Translation, and Text to Speech. You will only need the Speech to Text bit. Once you get it working with a microphone you can make use of the file inject to push your own audio files through the service.
For larger files you will need to make use of http post and multi-parts, when you get to that point, raise a new question, tag it with node-red and someone will post a sample flow for you.
You do not need to have any programming knowledge to use Watson Speech To Text. You can just send your files to the service using the curl tool. Which you can easily install in your computer, it is free.
Then you can send a file to the service running the following command:
curl -X POST -u "apikey:{apikey}" --header "Content-Type: audio/flac" --data-binary #audio-file2.flac "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize"
You just need an apikey to run that command, which you can get following these steps: https://cloud.ibm.com/docs/services/watson?topic=watson-iam
Then just replace the .flac file in that command by the file you want to process. And pass the right value for the Content-Type: header. For Flac files it is audio/flac, for other audio formats you have the list here: https://cloud.ibm.com/apidocs/speech-to-text
While reading on ZMQ, I encountered this link - A Web Server in 30 Lines of C. Highly motivated, I tried running the code and it does indeed print "Hello, World!"
Here's the problem: I never quite get the puts (request); to print anything. Essentially, I was looking for being able to send back some data based on query parrams. Example: http://localhost:8080/hello?myname=mho
response would change with sprintf of the name.
I believe I am not completely able to understand the code (:( just 30 lines!).
Any useful links on how the CZMQ is handling the frames? I am not sure, I am able to make good sense out of the inline documentation in the headers.
Any pointers? Happy to read through please.
Am I missing something obvious here?
I agree it's pretty neat, but it's not an HTTP server - it doesn't understand anything about HTTP, especially not how to parse a query string.
You can certainly use 0MQ to send messages very simply. The zguide has examples of many patterns in many languages - should be everything you need. You need to write both a client and server (really a sender and a receiver) to send anything meaningful over 0MQ. If you're hoping to use a generic http client like curl or wget, then use a real HTTP server instead of 0MQ. Many scripting languages let you launch an HTTP listener in a single line of code. Choose what best fits your needs. If you do use 0MQ, there is an IRC channel on Freenode where you can get help.
I wanted to upload a jpeg image file on the server.I have a GoAhead web server which supports only cgi c program as a serverside handeling.
Can any one know how to handle http posted image file in program witten in cgi in c language?
The GoAhead web server has a file upload filter for this purpose. The upload filter receives the uploaded file and saves it to disk. It then sets some request variables describing the upload. Those variables are accessible via CGI or via action functions or JST templates.
There is an example in test.c. Search for uploadTest().
See: https://github.com/embedthis/goahead/blob/master/test/test.c
To get POST data just read stdin. Environment variable CONTENT_LENGTH tells you how much to expect but of course you need to make your code robust against whatever a potentially malicious user can throw at you.
We have a PDF file download link on a web page with a C language CGI program actually passing on the file from our embedded device's web server. The web server is custom coded because of severe memory limitations.
The suggested filename by the C program is "Manual.pdf".
On Internet Explorer 8, when we click on the link the usual "Open/Save" box opens with the suggested filename displayed being "download.pdf" which is wrong. On Firefox, the suggested filename is "download.cgi" which is worse. However both browsers correctly indicate that the download is a PDF type.
Here are a few unrelated snippets of code to show the headers we are returning:
{ CONTENT_TYPE_PDF, "application/pdf\nContent-Disposition:attachment;" }
sprintf(tmpBuf, "Content-Type: %s\n", get_tbl_string((tbl_str_itm_t*)content_type, session->response.contenttype));
strcpy(tmpBuf, "filename=Manual.pdf\n");
strcat(tmpBuf, "Cache-Control: no-cache, no-store\n");
Can anyone tell what we are doing wrong?
Any help greatly appreciated.
Best regards,
Bert
The "filename" stuff is part of the content-disposition header.
Content-Disposition: attachment; filename=Manual.pdf header is good solution, however it doesn't work well if your filename has non-english characters. Another solution is to append "/Manual.pdf" path to your cgi script, i.e. use URLs like: http://server/path/my.cgi/Manual.pdf, and then your my.cgi program will be called with PATH_INFO=/Manual.pdf. For funky filenames, this works better than Content-Disposition header.
Update: If you are interested in browser support for Content-Disposition header, check http://greenbytes.de/tech/tc2231/.
Update: Another interesting article on the topic: Link
You might find some of the tips here useful:
http://blog.httpwatch.com/2010/03/24/four-tips-for-setting-up-http-file-downloads/
I have some C code that parses a file and generates another file of processed data. I now need to post these files to a website on a web server. I guess there is a way to do a HTTP POST but I have never done this in c (using GCC on Ubuntu). Does anyone know how to do this? I need a starting point as I have no clue of doing this in C. I also need to be able to authenticate with the website.
libcurl is probably a good place to start.
I think Hank Gay's suggestion of using a library to handle the details is the best one, but if you want to "do it yourself", you need to open a socket to the web server and then send your data in the HTTP POST format which is described here. Authentication can mean a variety of different things, so you need to be more specific.
Unfortunately, all of the above three jobs involve a fair bit of complexity, so you need to break the question down into stages and come back and ask about each bit separately.