Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab has been updated. More info
here
.
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
8f62822a
Commit
8f62822a
authored
11 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
Using mg_printf()
parent
0aa1a9e3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/post.c
+3
-5
3 additions, 5 deletions
examples/post.c
with
3 additions
and
5 deletions
examples/post.c
+
3
−
5
View file @
8f62822a
...
@@ -11,7 +11,7 @@ static const char *html_form =
...
@@ -11,7 +11,7 @@ static const char *html_form =
"</form></body></html>"
;
"</form></body></html>"
;
static
int
handler
(
struct
mg_connection
*
conn
)
{
static
int
handler
(
struct
mg_connection
*
conn
)
{
char
var1
[
500
],
var2
[
500
]
,
reply
[
2000
]
;
char
var1
[
500
],
var2
[
500
];
if
(
strcmp
(
conn
->
uri
,
"/handle_post_request"
)
==
0
)
{
if
(
strcmp
(
conn
->
uri
,
"/handle_post_request"
)
==
0
)
{
// User has submitted a form, show submitted data and a variable value
// User has submitted a form, show submitted data and a variable value
...
@@ -21,21 +21,19 @@ static int handler(struct mg_connection *conn) {
...
@@ -21,21 +21,19 @@ static int handler(struct mg_connection *conn) {
// Send reply to the client, showing submitted form values.
// Send reply to the client, showing submitted form values.
// POST data is in conn->content, data length is in conn->content_len
// POST data is in conn->content, data length is in conn->content_len
sn
printf
(
reply
,
sizeof
(
reply
)
,
"HTTP/1.0 200 OK
\r\n
"
mg_
printf
(
conn
,
"HTTP/1.0 200 OK
\r\n
"
"Content-Type: text/plain
\r\n\r\n
"
"Content-Type: text/plain
\r\n\r\n
"
"Submitted data: [%.*s]
\n
"
"Submitted data: [%.*s]
\n
"
"Submitted data length: %d bytes
\n
"
"Submitted data length: %d bytes
\n
"
"input_1: [%s]
\n
"
"input_1: [%s]
\n
"
"input_2: [%s]
\n
"
,
"input_2: [%s]
\n
"
,
conn
->
content_len
,
conn
->
content
,
conn
->
content_len
,
var1
,
var2
);
conn
->
content_len
,
conn
->
content
,
conn
->
content_len
,
var1
,
var2
);
mg_write
(
conn
,
reply
,
strlen
(
reply
));
}
else
{
}
else
{
// Show HTML form.
// Show HTML form.
sn
printf
(
reply
,
sizeof
(
reply
)
,
"HTTP/1.
0
200 OK
\r\n
"
mg_
printf
(
conn
,
"HTTP/1.
1
200 OK
\r\n
"
"Content-Length: %d
\r\n
"
"Content-Length: %d
\r\n
"
"Content-Type: text/html
\r\n\r\n
%s"
,
"Content-Type: text/html
\r\n\r\n
%s"
,
(
int
)
strlen
(
html_form
),
html_form
);
(
int
)
strlen
(
html_form
),
html_form
);
mg_write
(
conn
,
reply
,
strlen
(
reply
));
}
}
return
1
;
return
1
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment