Search results for 'QUERY_STRING'. 2 post(s) found.
- 2007/08/27 Simple CGI Programming in C
- 2007/08/27 How to send binary data through C# CGI app?
Here's the simplest C based CGI Example.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *data;
printf("Content-Type:text/html;\xd\xa"); // HTML out start !!
printf("<TITLE>Multiplication results</TITLE>\n");
printf("<H3>Multiplication results</H3>\n");
data = getenv("QUERY_STRING"); // getting parameters
if(data == NULL)
printf("<P>No Query string found");
else
printf("<P>%s", data);
return 0;
}
#include <stdlib.h>
int main(void)
{
char *data;
printf("Content-Type:text/html;\xd\xa"); // HTML out start !!
printf("<TITLE>Multiplication results</TITLE>\n");
printf("<H3>Multiplication results</H3>\n");
data = getenv("QUERY_STRING"); // getting parameters
if(data == NULL)
printf("<P>No Query string found");
else
printf("<P>%s", data);
return 0;
}
If you want to run this application on Apache platform, you can test this application by copying to Apache CGI-bin directory.
If it's compiled as test.exe and installed in Apache installed local PC, you can test it by following URL:
http://127.0.0.1/CGI-bin/test.exe
http://127.0.0.1/CGI-bin/test.exe?helloworld
Another posts included in "C, C++"
| Fast and Good Keyboard/Mouse Test without the message handler (0) | 2007/08/27 |
| Using the shell to receive notification of removable media being insert... (0) | 2007/08/28 |
| UDP Send and Receive Using CAsyncSocket (0) | 2007/08/28 |
| C++ CGI Example working on Apache (0) | 2007/08/27 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/29 00:20
moneyideas
-
Subject different money making ideas
2010/01/29 08:47
moneyideas
-
Subject different money making ideas
2010/01/31 16:44
moneyideas
Following example implemented binary data downloading.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace cscgi
{
class CsCGI
{
private static string dbgString = "id=1234&pic=123.gif";
private List<string> lstKeys = new List<string>();
private List<string> lstVals = new List<string>();
static void Main(string[] args)
{
CsCGI app = new CsCGI();
ParseParams(app);
string sID = GetParam(app, "id");
string sFile = GetParam(app, "pic");
try
{
FileStream fs = new FileStream(sFile, FileMode.Open);
BinaryReader brFile = new BinaryReader(fs, Encoding.UTF8);
byte[] bBuff = new byte[fs.Length];
brFile.Read(bBuff, 0, (int)fs.Length);
string sBuff = Encoding.ASCII.GetString(bBuff);
// if it's just text file, change binary/plain to text/html
Console.Write("Content-Type: binary/plain\n");
Console.Write("Content-Length: " + fs.Length.ToString());
Console.Write("\n\n");
Console.Write(sBuff);
}
catch (Exception e)
{
Console.Write(e.Message + "\n");
}
finally
{
//
}
}
private static void ParseParams(CsCGI app)
{
//string queryString = Environment.GetEnvironmentVariable("QUERY_STRING");
string queryString = dbgString;
string[] sParams = queryString.Split('&');
string[] sParamsSeperated;
for (int i = 0; i < sParams.Length; i++)
{
sParamsSeperated = sParamsIdea.Split('=');
app.lstKeys.Add(sParamsSeperated[0]);
app.lstVals.Add(sParamsSeperated[1]);
}
}
private static string GetParam(CsCGI app, string key)
{
int idx = app.lstKeys.BinarySearch(key);
if (idx >= 0)
return app.lstVals[idx];
return "";
}
}
}
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace cscgi
{
class CsCGI
{
private static string dbgString = "id=1234&pic=123.gif";
private List<string> lstKeys = new List<string>();
private List<string> lstVals = new List<string>();
static void Main(string[] args)
{
CsCGI app = new CsCGI();
ParseParams(app);
string sID = GetParam(app, "id");
string sFile = GetParam(app, "pic");
try
{
FileStream fs = new FileStream(sFile, FileMode.Open);
BinaryReader brFile = new BinaryReader(fs, Encoding.UTF8);
byte[] bBuff = new byte[fs.Length];
brFile.Read(bBuff, 0, (int)fs.Length);
string sBuff = Encoding.ASCII.GetString(bBuff);
// if it's just text file, change binary/plain to text/html
Console.Write("Content-Type: binary/plain\n");
Console.Write("Content-Length: " + fs.Length.ToString());
Console.Write("\n\n");
Console.Write(sBuff);
}
catch (Exception e)
{
Console.Write(e.Message + "\n");
}
finally
{
//
}
}
private static void ParseParams(CsCGI app)
{
//string queryString = Environment.GetEnvironmentVariable("QUERY_STRING");
string queryString = dbgString;
string[] sParams = queryString.Split('&');
string[] sParamsSeperated;
for (int i = 0; i < sParams.Length; i++)
{
sParamsSeperated = sParamsIdea.Split('=');
app.lstKeys.Add(sParamsSeperated[0]);
app.lstVals.Add(sParamsSeperated[1]);
}
}
private static string GetParam(CsCGI app, string key)
{
int idx = app.lstKeys.BinarySearch(key);
if (idx >= 0)
return app.lstVals[idx];
return "";
}
}
}
If you are using Apache and wanna test it just put the EXE in the cgi-bin folder under Apache's directory. Also note that the parameters are static just for this example.
Another posts included in "C#"
| Simple C# CGI working on Apache (0) | 2007/08/27 |
| Simple Example Of IF/THEN Using C# (0) | 2007/08/28 |
| C Sharp Lists (0) | 2007/08/28 |
| Interacting With TinyPic From C# (0) | 2007/08/27 |
| Creating A Watched Folder With Assigned Events (0) | 2007/08/27 |
| Calling Your Main Thread From A Worker Thread In C# (0) | 2007/08/27 |
| HashTable Tutorial In C# (0) | 2007/08/27 |
| Stack Tutorial In C# (0) | 2007/08/27 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/29 02:25
moneyideas
-
Subject different money making ideas
2010/01/29 10:53
moneyideas
-
Subject different money making ideas
2010/01/31 16:44
moneyideas

Prev

Rss Feed