Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
c82ccd6c
Commit
c82ccd6c
authored
9 years ago
by
Marko Mikulicic
Committed by
rojer
9 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify http client example
PUBLISHED_FROM=64a91c5d261338c7c224340943d63d4b753ee303
parent
0adb0803
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
12 deletions
+7
-12
restful_client.c
examples/restful_client/restful_client.c
+7
-12
No files found.
examples/restful_client/restful_client.c
View file @
c82ccd6c
...
@@ -6,8 +6,8 @@
...
@@ -6,8 +6,8 @@
#include "mongoose.h"
#include "mongoose.h"
/* RESTful server host and request URI */
/* RESTful server host and request URI */
static
const
char
*
s_
target_address
=
"ajax.googleapis.com:80"
;
static
const
char
*
s_
url
=
static
const
char
*
s_request
=
"
/ajax/services/search/web?v=1.0&q=cesanta"
;
"http://ajax.googleapis.com
/ajax/services/search/web?v=1.0&q=cesanta"
;
static
int
s_exit_flag
=
0
;
static
int
s_exit_flag
=
0
;
...
@@ -17,14 +17,9 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
...
@@ -17,14 +17,9 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
switch
(
ev
)
{
switch
(
ev
)
{
case
MG_EV_CONNECT
:
case
MG_EV_CONNECT
:
connect_status
=
*
(
int
*
)
ev_data
;
connect_status
=
*
(
int
*
)
ev_data
;
if
(
connect_status
==
0
)
{
if
(
connect_status
!=
0
)
{
printf
(
"Connected to %s, sending request...
\n
"
,
s_target_address
);
printf
(
"Error connecting to %s: %s
\n
"
,
s_url
,
strerror
(
connect_status
));
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
));
s_exit_flag
=
1
;
s_exit_flag
=
1
;
}
}
break
;
break
;
...
@@ -43,10 +38,10 @@ int main(void) {
...
@@ -43,10 +38,10 @@ int main(void) {
struct
mg_connection
*
nc
;
struct
mg_connection
*
nc
;
mg_mgr_init
(
&
mgr
,
NULL
);
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
);
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
)
{
while
(
s_exit_flag
==
0
)
{
mg_mgr_poll
(
&
mgr
,
1000
);
mg_mgr_poll
(
&
mgr
,
1000
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment