Sample Code - Linux API
Jump to navigation
Jump to search
HTTP Parser - PHP[edit | edit source]
<?php
//
// HTTP POST test page, using PHP
//
// appends any incoming POSTs into $filename, and
// decomposes any URLENCODED strings on the next line.
//
// (c) 2009 Venture Research Inc. Free for any use.
// Uses the example from http://us.php.net/fwrite.
//
// set initial filename to be appended to
$filename = 'C:\tags.txt';
$somecontent = "";
// Make sure the user is posting
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
// Read the input from stdin
$somecontent = trim(file_get_contents('php://input')) . "\r\n\r\n";
// decompose the REQUEST input into key and value pairs (URLENCODED mode)
foreach( $_REQUEST as $key => $value){
$somecontent .= "$key => $value,";
}
$somecontent .= "\r\n";
}
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
//echo "Success, wrote ($somecontent) to file ($filename)";
echo "Success";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
HTTP Parser - ASPX[edit | edit source]
Partial Class Upload
Inherits System.Web.UI.Page
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strReply As String = "Success" 'A CallHome response, instead of Success, will trigger the Reader to connect back to VR - Diagnostic Socket
Dim strResult as String = "[" & Request.ServerVariables("remote_addr") & "] "
For Each k as String in Request.Form
strResult &= k & ": " & Request.Form[k] & ", "
Next
If ConfigurationManager.AppSettings("EnableLogging").ToLower = "true" Then
Using sw As System.IO.StreamWriter = New System.IO.StreamWriter(ConfigurationManager.AppSettings("LogResults"), True)
sw.WriteLine(strResult)
End Using
End If
Response.Clear()
Response.Write(strReply & vbCrLf)
Response.End()
End Sub
End Class