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
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
c82ccd6c
Commit
c82ccd6c
authored
9 years ago
by
Marko Mikulicic
Committed by
rojer
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Simplify http client example
PUBLISHED_FROM=64a91c5d261338c7c224340943d63d4b753ee303
parent
0adb0803
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/restful_client/restful_client.c
+7
-12
7 additions, 12 deletions
examples/restful_client/restful_client.c
with
7 additions
and
12 deletions
examples/restful_client/restful_client.c
+
7
−
12
View file @
c82ccd6c
...
...
@@ -6,8 +6,8 @@
#include
"mongoose.h"
/* RESTful server host and request URI */
static
const
char
*
s_
target_address
=
"ajax.googleapis.com:80"
;
static
const
char
*
s_request
=
"
/ajax/services/search/web?v=1.0&q=cesanta"
;
static
const
char
*
s_
url
=
"http://ajax.googleapis.com
/ajax/services/search/web?v=1.0&q=cesanta"
;
static
int
s_exit_flag
=
0
;
...
...
@@ -17,14 +17,9 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
switch
(
ev
)
{
case
MG_EV_CONNECT
:
connect_status
=
*
(
int
*
)
ev_data
;
if
(
connect_status
==
0
)
{
printf
(
"Connected to %s, sending request...
\n
"
,
s_target_address
);
mg_printf
(
nc
,
"GET %s HTTP/1.0
\r\n
Host: %s
\r\n\r\n
"
,
s_request
,
s_target_address
);
}
else
{
printf
(
"Error connecting to %s: %s
\n
"
,
s_target_address
,
strerror
(
connect_status
));
connect_status
=
*
(
int
*
)
ev_data
;
if
(
connect_status
!=
0
)
{
printf
(
"Error connecting to %s: %s
\n
"
,
s_url
,
strerror
(
connect_status
));
s_exit_flag
=
1
;
}
break
;
...
...
@@ -43,10 +38,10 @@ int main(void) {
struct
mg_connection
*
nc
;
mg_mgr_init
(
&
mgr
,
NULL
);
nc
=
mg_connect
(
&
mgr
,
s_target_address
,
ev_handler
);
nc
=
mg_connect
_http
(
&
mgr
,
ev_handler
,
s_url
,
NULL
,
NULL
);
mg_set_protocol_http_websocket
(
nc
);
printf
(
"Starting RESTful client against %s
\n
"
,
s_
target_address
);
printf
(
"Starting RESTful client against %s
\n
"
,
s_
url
);
while
(
s_exit_flag
==
0
)
{
mg_mgr_poll
(
&
mgr
,
1000
);
}
...
...
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