503 - Service temporarily unavailable












1















I need simple HTTP client on Raspberry PI zero with Raspbian. I used few example codes, but when i send about 7 requests then i can download just page with this error:
503 Service temporarily unavailable
There is no available fastcgi process to fullfill your request.



One of used codes:



#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netdb.h>
#include <unistd.h>
#define SA struct sockaddr
#define MAXLINE 4096
#define MAXSUB 200

ssize_t process_http(int sockfd, char *host, char *page)
{
ssize_t n;
snprintf(sendline, MAXSUB,
"GET %srn"
"Host: %srn"
"Connection: closen"
"n", page, host);

write(sockfd, sendline, strlen(sendline));

while ((n = read(sockfd, recvline, MAXLINE)) > 0)
{
recvline[n] = '';
}
printf("%s", recvline);


return n;
}


and in main is this:



 int sockfd;
struct sockaddr_in servaddr;

char **pptr;

char *hname = "plankter.cz";
char *page = "http://plankter.cz/iot/list.json";

char str[50];
struct hostent *hptr;
if ((hptr = gethostbyname(hname)) == NULL) {
fprintf(stderr, " gethostbyname error for host: %s: %s",
hname, hstrerror(h_errno));
exit(1);
}
printf("hostname: %sn", hptr->h_name);
if (hptr->h_addrtype == AF_INET
&& (pptr = hptr->h_addr_list) != NULL) {
printf("address: %sn",
inet_ntop(hptr->h_addrtype, *pptr, str,
sizeof(str)));
} else {
fprintf(stderr, "Error call inet_ntop n");
}

sockfd = socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(80);
inet_pton(AF_INET, str, &servaddr.sin_addr);

connect(sockfd, (SA *) & servaddr, sizeof(servaddr));
process_http(sockfd, hname, page);
close(sockfd);


In this example i download json, but when i read php or txt, i have same problem. I tried some another example codes using sockets, example with happyhttp library and all give me same result after 7 requests. I think it doesn't close connection. I need to send http request and recieve data, and i need to do it few times in minute.



Thanks for all ideas.










share|improve this question

























  • That is C code. Why do you say C/C++?

    – Giovanni Cerretani
    Nov 21 '18 at 8:54











  • It's possible you're hitting a rate limit on the web server you're contacting. Try sending the requests slower (eg. add a sleep between subsequent requests).

    – Sander De Dycker
    Nov 21 '18 at 9:00













  • Did you verify the content of your packets with Wireshark?

    – Gerhardh
    Nov 21 '18 at 9:05
















1















I need simple HTTP client on Raspberry PI zero with Raspbian. I used few example codes, but when i send about 7 requests then i can download just page with this error:
503 Service temporarily unavailable
There is no available fastcgi process to fullfill your request.



One of used codes:



#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netdb.h>
#include <unistd.h>
#define SA struct sockaddr
#define MAXLINE 4096
#define MAXSUB 200

ssize_t process_http(int sockfd, char *host, char *page)
{
ssize_t n;
snprintf(sendline, MAXSUB,
"GET %srn"
"Host: %srn"
"Connection: closen"
"n", page, host);

write(sockfd, sendline, strlen(sendline));

while ((n = read(sockfd, recvline, MAXLINE)) > 0)
{
recvline[n] = '';
}
printf("%s", recvline);


return n;
}


and in main is this:



 int sockfd;
struct sockaddr_in servaddr;

char **pptr;

char *hname = "plankter.cz";
char *page = "http://plankter.cz/iot/list.json";

char str[50];
struct hostent *hptr;
if ((hptr = gethostbyname(hname)) == NULL) {
fprintf(stderr, " gethostbyname error for host: %s: %s",
hname, hstrerror(h_errno));
exit(1);
}
printf("hostname: %sn", hptr->h_name);
if (hptr->h_addrtype == AF_INET
&& (pptr = hptr->h_addr_list) != NULL) {
printf("address: %sn",
inet_ntop(hptr->h_addrtype, *pptr, str,
sizeof(str)));
} else {
fprintf(stderr, "Error call inet_ntop n");
}

sockfd = socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(80);
inet_pton(AF_INET, str, &servaddr.sin_addr);

connect(sockfd, (SA *) & servaddr, sizeof(servaddr));
process_http(sockfd, hname, page);
close(sockfd);


In this example i download json, but when i read php or txt, i have same problem. I tried some another example codes using sockets, example with happyhttp library and all give me same result after 7 requests. I think it doesn't close connection. I need to send http request and recieve data, and i need to do it few times in minute.



Thanks for all ideas.










share|improve this question

























  • That is C code. Why do you say C/C++?

    – Giovanni Cerretani
    Nov 21 '18 at 8:54











  • It's possible you're hitting a rate limit on the web server you're contacting. Try sending the requests slower (eg. add a sleep between subsequent requests).

    – Sander De Dycker
    Nov 21 '18 at 9:00













  • Did you verify the content of your packets with Wireshark?

    – Gerhardh
    Nov 21 '18 at 9:05














1












1








1








I need simple HTTP client on Raspberry PI zero with Raspbian. I used few example codes, but when i send about 7 requests then i can download just page with this error:
503 Service temporarily unavailable
There is no available fastcgi process to fullfill your request.



One of used codes:



#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netdb.h>
#include <unistd.h>
#define SA struct sockaddr
#define MAXLINE 4096
#define MAXSUB 200

ssize_t process_http(int sockfd, char *host, char *page)
{
ssize_t n;
snprintf(sendline, MAXSUB,
"GET %srn"
"Host: %srn"
"Connection: closen"
"n", page, host);

write(sockfd, sendline, strlen(sendline));

while ((n = read(sockfd, recvline, MAXLINE)) > 0)
{
recvline[n] = '';
}
printf("%s", recvline);


return n;
}


and in main is this:



 int sockfd;
struct sockaddr_in servaddr;

char **pptr;

char *hname = "plankter.cz";
char *page = "http://plankter.cz/iot/list.json";

char str[50];
struct hostent *hptr;
if ((hptr = gethostbyname(hname)) == NULL) {
fprintf(stderr, " gethostbyname error for host: %s: %s",
hname, hstrerror(h_errno));
exit(1);
}
printf("hostname: %sn", hptr->h_name);
if (hptr->h_addrtype == AF_INET
&& (pptr = hptr->h_addr_list) != NULL) {
printf("address: %sn",
inet_ntop(hptr->h_addrtype, *pptr, str,
sizeof(str)));
} else {
fprintf(stderr, "Error call inet_ntop n");
}

sockfd = socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(80);
inet_pton(AF_INET, str, &servaddr.sin_addr);

connect(sockfd, (SA *) & servaddr, sizeof(servaddr));
process_http(sockfd, hname, page);
close(sockfd);


In this example i download json, but when i read php or txt, i have same problem. I tried some another example codes using sockets, example with happyhttp library and all give me same result after 7 requests. I think it doesn't close connection. I need to send http request and recieve data, and i need to do it few times in minute.



Thanks for all ideas.










share|improve this question
















I need simple HTTP client on Raspberry PI zero with Raspbian. I used few example codes, but when i send about 7 requests then i can download just page with this error:
503 Service temporarily unavailable
There is no available fastcgi process to fullfill your request.



One of used codes:



#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netdb.h>
#include <unistd.h>
#define SA struct sockaddr
#define MAXLINE 4096
#define MAXSUB 200

ssize_t process_http(int sockfd, char *host, char *page)
{
ssize_t n;
snprintf(sendline, MAXSUB,
"GET %srn"
"Host: %srn"
"Connection: closen"
"n", page, host);

write(sockfd, sendline, strlen(sendline));

while ((n = read(sockfd, recvline, MAXLINE)) > 0)
{
recvline[n] = '';
}
printf("%s", recvline);


return n;
}


and in main is this:



 int sockfd;
struct sockaddr_in servaddr;

char **pptr;

char *hname = "plankter.cz";
char *page = "http://plankter.cz/iot/list.json";

char str[50];
struct hostent *hptr;
if ((hptr = gethostbyname(hname)) == NULL) {
fprintf(stderr, " gethostbyname error for host: %s: %s",
hname, hstrerror(h_errno));
exit(1);
}
printf("hostname: %sn", hptr->h_name);
if (hptr->h_addrtype == AF_INET
&& (pptr = hptr->h_addr_list) != NULL) {
printf("address: %sn",
inet_ntop(hptr->h_addrtype, *pptr, str,
sizeof(str)));
} else {
fprintf(stderr, "Error call inet_ntop n");
}

sockfd = socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(80);
inet_pton(AF_INET, str, &servaddr.sin_addr);

connect(sockfd, (SA *) & servaddr, sizeof(servaddr));
process_http(sockfd, hname, page);
close(sockfd);


In this example i download json, but when i read php or txt, i have same problem. I tried some another example codes using sockets, example with happyhttp library and all give me same result after 7 requests. I think it doesn't close connection. I need to send http request and recieve data, and i need to do it few times in minute.



Thanks for all ideas.







c sockets raspberry-pi raspbian






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 11:03









Giovanni Cerretani

581317




581317










asked Nov 21 '18 at 8:34









Radek ČudekRadek Čudek

82




82













  • That is C code. Why do you say C/C++?

    – Giovanni Cerretani
    Nov 21 '18 at 8:54











  • It's possible you're hitting a rate limit on the web server you're contacting. Try sending the requests slower (eg. add a sleep between subsequent requests).

    – Sander De Dycker
    Nov 21 '18 at 9:00













  • Did you verify the content of your packets with Wireshark?

    – Gerhardh
    Nov 21 '18 at 9:05



















  • That is C code. Why do you say C/C++?

    – Giovanni Cerretani
    Nov 21 '18 at 8:54











  • It's possible you're hitting a rate limit on the web server you're contacting. Try sending the requests slower (eg. add a sleep between subsequent requests).

    – Sander De Dycker
    Nov 21 '18 at 9:00













  • Did you verify the content of your packets with Wireshark?

    – Gerhardh
    Nov 21 '18 at 9:05

















That is C code. Why do you say C/C++?

– Giovanni Cerretani
Nov 21 '18 at 8:54





That is C code. Why do you say C/C++?

– Giovanni Cerretani
Nov 21 '18 at 8:54













It's possible you're hitting a rate limit on the web server you're contacting. Try sending the requests slower (eg. add a sleep between subsequent requests).

– Sander De Dycker
Nov 21 '18 at 9:00







It's possible you're hitting a rate limit on the web server you're contacting. Try sending the requests slower (eg. add a sleep between subsequent requests).

– Sander De Dycker
Nov 21 '18 at 9:00















Did you verify the content of your packets with Wireshark?

– Gerhardh
Nov 21 '18 at 9:05





Did you verify the content of your packets with Wireshark?

– Gerhardh
Nov 21 '18 at 9:05












1 Answer
1






active

oldest

votes


















0














You provide a full URI to the GET field:



char *page = "http://plankter.cz/iot/list.json";
...
snprintf(sendline, MAXSUB,
"GET %srn"
"Host: %srn"
"Connection: closen"
"n", page, host);


You should not include protocol and host name.



Try this instead:



char *page = "/iot/list.json";





share|improve this answer
























  • Thank you, it works.

    – Radek Čudek
    Nov 22 '18 at 13:20











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408016%2f503-service-temporarily-unavailable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You provide a full URI to the GET field:



char *page = "http://plankter.cz/iot/list.json";
...
snprintf(sendline, MAXSUB,
"GET %srn"
"Host: %srn"
"Connection: closen"
"n", page, host);


You should not include protocol and host name.



Try this instead:



char *page = "/iot/list.json";





share|improve this answer
























  • Thank you, it works.

    – Radek Čudek
    Nov 22 '18 at 13:20
















0














You provide a full URI to the GET field:



char *page = "http://plankter.cz/iot/list.json";
...
snprintf(sendline, MAXSUB,
"GET %srn"
"Host: %srn"
"Connection: closen"
"n", page, host);


You should not include protocol and host name.



Try this instead:



char *page = "/iot/list.json";





share|improve this answer
























  • Thank you, it works.

    – Radek Čudek
    Nov 22 '18 at 13:20














0












0








0







You provide a full URI to the GET field:



char *page = "http://plankter.cz/iot/list.json";
...
snprintf(sendline, MAXSUB,
"GET %srn"
"Host: %srn"
"Connection: closen"
"n", page, host);


You should not include protocol and host name.



Try this instead:



char *page = "/iot/list.json";





share|improve this answer













You provide a full URI to the GET field:



char *page = "http://plankter.cz/iot/list.json";
...
snprintf(sendline, MAXSUB,
"GET %srn"
"Host: %srn"
"Connection: closen"
"n", page, host);


You should not include protocol and host name.



Try this instead:



char *page = "/iot/list.json";






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 9:09









GerhardhGerhardh

3,9172725




3,9172725













  • Thank you, it works.

    – Radek Čudek
    Nov 22 '18 at 13:20



















  • Thank you, it works.

    – Radek Čudek
    Nov 22 '18 at 13:20

















Thank you, it works.

– Radek Čudek
Nov 22 '18 at 13:20





Thank you, it works.

– Radek Čudek
Nov 22 '18 at 13:20


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408016%2f503-service-temporarily-unavailable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?