#include#include #include /* CGI Testing Method: POSTplease input two number:* =*/char InputBuffer[4096]; int DecodeAndProcessData(char *input); /*具体译码和处理数据,该函数代码略*/ int main(int argc, char*argv[]) { int ContentLength; /*数据长度*/ int x; int i; char *p; char *pRequestMethod; /* METHOD属性值 */ setvbuf(stdin,NULL,_IONBF,0); /*关闭stdin的缓冲*/ printf("Content-type:text/html\n\n"); /*从stdout中输出,告诉Web服务器返回的信息类型*/ printf("\n"); /*插入一个空行,结束头部信息*/ //printf("
hello test
"); /* 从环境变量REQUEST_METHOD中得到METHOD属性值 */ pRequestMethod = getenv("REQUEST_METHOD"); if(pRequestMethod==NULL) { printf("request = null
"); return 0; } if (strcmp(pRequestMethod,"POST")==0) { //printf("OK the method is POST!\n
"); p = getenv("CONTENT_LENGTH"); //从环境变量CONTENT_LENGTH中得到数据长度 if (p!=NULL) { ContentLength = atoi(p); } else { ContentLength = 0; } if (ContentLength > sizeof(InputBuffer)-1) { ContentLength = sizeof (InputBuffer) - 1; } i = 0; while (i < ContentLength) { //从stdin中得到Form数据 x = fgetc(stdin); if (x==EOF) break; InputBuffer[i++] = x; } InputBuffer[i] = '\0'; ContentLength = i; DecodeAndProcessData(InputBuffer); //具体译码和处理数据,该函数代码略 } else if (strcmp(pRequestMethod,"GET")==0) { //printf("OK the method is GET!\n
"); p = getenv("QUERY_STRING"); //从环境变量QUERY_STRING中得到Form数据 if (p!=NULL) { strncpy(InputBuffer,p,sizeof(InputBuffer)); DecodeAndProcessData(InputBuffer); //具体译码和处理数据,该函数代码略 } } //printf("Submitted OK \n");//从stdout中输出返回信息 //printf("The information you supplied has been accepted.\n"); return 0; } int DecodeAndProcessData(char *input) //具体译码和处理数据 { printf("%s",input);//输出到客户端 // 补充具体操作 /*int i; int len; len = (int)strlen(input); printf("data length:"+len); for(i = 0;i < len;i++) { printf(">>:%d\n",input[i]); }*/ return 0; }
unity3D 获取数据
using UnityEngine;using System.Collections;public class NewBehaviourScript : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void Awake() { TestHttpSend(); } IEnumerator SendPost(string _url, WWWForm _wForm) { WWW postData = new WWW(_url, _wForm); yield return postData; if (postData.error != null) { Debug.Log(postData.error); } else { Debug.Log("|"+postData.text+"|"); } } public void TestHttpSend() { //测试POST方法 WWWForm form = new WWWForm(); form.AddField("int", "6"); form.AddField("value", 2); /* byte[] b = new byte[2]; b[0] = 1; b[1] = 2; form.AddBinaryData("myBytes", b,"file.dat",""); */ StartCoroutine(SendPost("http://127.0.0.1:10086/cgi-bin/gt.cgi", form)); }}
unity3D获取的数据
|int=6&value=2|