0

xml本体を含むPOSTリクエストを解析する単純なCWebサーバーを作成しています。返信を返送しようとしていますが、うまくいかないようです。これが私のコードです:

char res[2000];
strcpy(res, "HTTP/1.1 201 OK\nContent-Type: text/html\n");

printf("%s", res);;
char re[4026];
strcpy(re,"<html><body><p>");
strcat(re, result);
strcat(re, "</p></body></html>\n");
printf("\n%s\n", re);

char tm[1000];
sprintf(tm, "Content-Length: ");
char len[4035];
int l= strlen(re);
sprintf(len, "%d\n", l);
printf("\n%s\n", len);
strcat(tm, len);
printf("\n%s\n", tm);

strcat(res, tm);
strcat(res, re);
printf("\n%s", res);
strcat(res, "\0");

send(sock, res, strlen(res),0);

理由はわかりませんが、送信すると通知が届き、ループにとどまります。

コードを理解するのが少し難しい場合に備えて、これはimが生成している文字列です。

HTTP/1.1 201 OK
Content-Type: text/html
Content-Length: 37
<html><body><p>139</p></body></html>
4

1 に答える 1

2

ヘッダーの後、本体の前に別の新しい行が必要です。

HTTP/1.1 201 OK
Content-Type: text/html
Content-Length: 37

<html><body><p>139</p></body></html>
于 2013-02-23T20:31:31.243 に答える