-3

Questions like this and this show you how to send an HTTP POST request using Cocoa and objective-c.

Is there any way to use that code in C? Furthermore, how to send an HTTPS (SSL) POST request using C on Mac OS X?

Thanks for the help

EDIT:

IF you don't like the fact that I am asking this question please stay away, do not vote it down. You might not need this but I do, that's why I asked. The same way i do not vote down on questions that seem pointless to me, please do not vote down on questions that are not important to you. Thank you.

Community
  • 1
  • 1
Mr Aleph
  • 1,887
  • 5
  • 28
  • 44
  • 10
    Take a look at libcurl. It’s a C library that’s part of any stock OS X installation. –  Oct 20 '11 at 20:01
  • Thank, I don't want to have to add yet another dependency to my project, unless it's just a simple adding a header. examples? I mean, having to figure out how to call a function on a lib like that is quite a bit of business, if you have sample code or can point me to a site with a concise sample I would appreciate it – Mr Aleph Oct 20 '11 at 20:53
  • 1
    You need to `#import ` and to add libcurl.dylib to the list of linked frameworks and libraries. There are several examples of using libcurl on the Web, but I’m not sure how libcurl deals with OS X keychain for certificates and private keys for SSL. Maybe someone else knows more about this and posts an answer. –  Oct 20 '11 at 20:55
  • This is what I mean by adding yet another dependency, beyond that take a look at their [examples](http://curl.haxx.se/libcurl/c/simplessl.html) it's impossible. – Mr Aleph Oct 20 '11 at 20:57
  • or [this](http://curl.haxx.se/libcurl/c/postit2.html) one. I am getting lost trying to understand their man pages. Anyone has an example of how to set an HTTPS POST using libcurl? Anyone? – Mr Aleph Oct 20 '11 at 20:58
  • Furthermore, check [sample](http://stackoverflow.com/questions/3486007/creating-libcurl-http-post-form). What? How? – Mr Aleph Oct 20 '11 at 21:03

2 Answers2

1

Core Foundation is C, and includes very nice HTTP support:

Communicating with HTTP Servers

The snippet is for GET, but POST is supported and straightforward. Here's a snippet that does use POST. Core Foundation is fully supported, 64-bit, iOS, an essential Mac OS and iOS API.

An answer to a JSON question

Community
  • 1
  • 1
Paul Collins
  • 361
  • 3
  • 11
  • Thanks. Where do I set the payload for post? I can't find any information about it – Mr Aleph Oct 21 '11 at 13:05
  • That's in the JSON answer snippet. The payload is the body, set with CFHTTPMessageSetBody(). You have to build up the string of keys and values to put in there. For another example, see http://www.mactech.com/articles/mactech/Vol.19/19.03/HTTPMessages/index.html – Paul Collins Oct 21 '11 at 17:31
0

With C you can use http://www.columbia.edu/kermit/ck90.html#source - it comes with make files for OSX 10.3 and up and has SSL etc. included... another option is http://curl.haxx.se/libcurl/c/

If you can use Objective-C you can do that for exmaple with http://allseeing-i.com/ASIHTTPRequest/ or http://www.chilkatsoft.com/http-objc.asp

Yahia
  • 69,653
  • 9
  • 115
  • 144
  • 1
    He asked for C ways, **not** objective-c – Amit Oct 20 '11 at 20:10
  • So, you want my only choice is to download a 3rd party lib? I've used cocoa APIs from C before. I'm sure I can use these as well, I just haven't found a way. – Mr Aleph Oct 20 '11 at 20:27
  • I don't want nothing... just provided some help regarding your question... since I don't use Cocoa I can't help you with a sample... perhaps someone else can... – Yahia Oct 20 '11 at 20:29
  • Thanks. But I rather use Cocoa via C. – Mr Aleph Oct 20 '11 at 20:39
  • @MrAleph Bear in mind that Cocoa exports an Objective-C API. There’s little Cocoa you can do with C only bar trying to program in Objective-C using the runtime API. –  Oct 20 '11 at 20:58
  • Thanks, i got your point. However, as I showed you it is impossible to try to figure how to use a lib like libcurl and so far no one gives you a concise example, everyone is: take a look at X. Sure, give me an example of why I should look at X – Mr Aleph Oct 20 '11 at 21:00