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
Mar 04, 2016
by
Marko Mikulicic
Committed by
rojer
Mar 08, 2016
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 @@
#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
);
}
...
...
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