doom3-gpl
Doom 3 GPL source release
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
neo
curl
docs
examples
postit2.c
Go to the documentation of this file.
1
/*****************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* $Id: postit2.c,v 1.2 2003/11/19 08:21:34 bagder Exp $
9
*
10
* Example code that uploads a file name 'foo' to a remote script that accepts
11
* "HTML form based" (as described in RFC1738) uploads using HTTP POST.
12
*
13
* The imaginary form we'll fill in looks like:
14
*
15
* <form method="post" enctype="multipart/form-data" action="examplepost.cgi">
16
* Enter file: <input type="file" name="sendfile" size="40">
17
* Enter file name: <input type="text" name="filename" size="30">
18
* <input type="submit" value="send" name="submit">
19
* </form>
20
*
21
* This exact source code has not been verified to work.
22
*/
23
24
#include <stdio.h>
25
#include <string.h>
26
27
#include <
curl/curl.h
>
28
#include <
curl/types.h
>
29
#include <
curl/easy.h
>
30
31
int
main
(
int
argc,
char
*argv[])
32
{
33
CURL
*curl;
34
CURLcode
res
;
35
36
struct
HttpPost *formpost=
NULL
;
37
struct
HttpPost *lastptr=
NULL
;
38
struct
curl_slist
*headerlist=
NULL
;
39
char
buf[] =
"Expect:"
;
40
41
curl_global_init
(
CURL_GLOBAL_ALL
);
42
43
/* Fill in the file upload field */
44
curl_formadd
(&formpost,
45
&lastptr,
46
CURLFORM_COPYNAME,
"sendfile"
,
47
CURLFORM_FILE,
"postit2.c"
,
48
CURLFORM_END);
49
50
/* Fill in the filename field */
51
curl_formadd
(&formpost,
52
&lastptr,
53
CURLFORM_COPYNAME,
"filename"
,
54
CURLFORM_COPYCONTENTS,
"postit2.c"
,
55
CURLFORM_END);
56
57
58
/* Fill in the submit field too, even if this is rarely needed */
59
curl_formadd
(&formpost,
60
&lastptr,
61
CURLFORM_COPYNAME,
"submit"
,
62
CURLFORM_COPYCONTENTS,
"send"
,
63
CURLFORM_END);
64
65
curl =
curl_easy_init
();
66
/* initalize custom header list (stating that Expect: 100-continue is not
67
wanted */
68
headerlist =
curl_slist_append
(headerlist, buf);
69
if
(curl) {
70
/* what URL that receives this POST */
71
curl_easy_setopt
(curl, CURLOPT_URL,
"http://curl.haxx.se/examplepost.cgi"
);
72
if
( (argc == 2) && (!
strcmp
(argv[1],
"noexpectheader"
)) )
73
/* only disable 100-continue header if explicitly requested */
74
curl_easy_setopt
(curl, CURLOPT_HTTPHEADER, headerlist);
75
curl_easy_setopt
(curl, CURLOPT_HTTPPOST, formpost);
76
res =
curl_easy_perform
(curl);
77
78
/* always cleanup */
79
curl_easy_cleanup
(curl);
80
81
/* then cleanup the formpost chain */
82
curl_formfree
(formpost);
83
/* free slist */
84
curl_slist_free_all
(headerlist);
85
}
86
return
0;
87
}
curl_global_init
CURLcode curl_global_init(long flags)
Globally initializes cURL given a bitwise set of the different features to initialize.
Definition:
easy.c:147
strcmp
#define strcmp
Definition:
Str.h:41
types.h
curl_slist
Definition:
curl.h:1061
curl_formadd
CURLFORMcode curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post,...)
Definition:
formdata.c:978
easy.h
curl_easy_perform
CURLcode curl_easy_perform(CURL *curl)
Definition:
easy.c:260
CURLcode
CURLcode
Definition:
curl.h:209
curl.h
curl_easy_setopt
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
Definition:
easy.c:217
NULL
#define NULL
Definition:
Lib.h:88
curl_formfree
void curl_formfree(struct curl_httppost *form)
Definition:
formdata.c:1073
curl_slist_append
struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
Definition:
sendf.c:82
CURL
void CURL
Definition:
types.h:25
curl_slist_free_all
void curl_slist_free_all(struct curl_slist *)
Definition:
sendf.c:108
res
GLuint res
Definition:
glext.h:5385
main
int main(int argc, char *argv[])
Definition:
postit2.c:31
CURL_GLOBAL_ALL
#define CURL_GLOBAL_ALL
Definition:
curl.h:1153
curl_easy_cleanup
void curl_easy_cleanup(CURL *curl)
Definition:
easy.c:288
curl_easy_init
CURL * curl_easy_init(void)
Definition:
easy.c:195
This page is maintained by
Wladimir van der Laan
. Generated on Mon Nov 17 2014 12:23:14 for doom3-gpl by
1.8.6
.