當前位置:編程學習大全網 - 網站源碼 - cgi程序如何接收Qt客戶端參數?

cgi程序如何接收Qt客戶端參數?

以下的程序測試過了,可以滿足妳的要求了。

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int main()

{

//輸出HTTP頭

printf("Content-type: text/plain\n\n");

//從CONTENT_LENGTH環境變量中取出其值

int n = atoi(getenv("CONTENT_LENGTH"));

printf("%d\n", n);

char buf[20];

memset(buf, 0, sizeof(buf));

//從stdin標準輸入流中讀取數據

fgets(buf, n, stdin);

//輸出

printf("Hi, this is CGI with c\n");

printf("%s\n", buf);

return 0;

}

大致流程妳都懂,就是有些細節不清楚吧。從stdin讀取數據時,首先要知道讀多長的數據,而這個長度保存在“CONTENT_LENGTH‘整個環境變量中。另外從stdin讀取數據要用fgets函數,scanf不是用在網絡通信中讀取數據用的。

  • 上一篇:酒店和手機產品有哪些內容?
  • 下一篇:如何用js改變多個框架的css,也就是讓網頁整體換膚
  • copyright 2024編程學習大全網