How to retrieve raw HTTP Post Data

M

manheim

I have a page posting a raw jpg to me via HTTP POST. All reference
I've found is centered around retrieving POST data as name/value pairs
which will not work in this situation.
What I need to do is retrieve the raw POST data and save it as a
jpg.

Here is some php code that does the same thing for reference:
$jfh = fopen($jpeg_file, 'w') or die("can't open file");
fwrite($jfh, $GLOBALS['HTTP_RAW_POST_DATA']);
fclose($jfh);

I assume there is some way to access POST data as a stream and then
write that stream to a file, but it's not clear to me how. Perhaps I
need to use Request.Form.GetObjectData, but I'm not sure how to setup
SerializationInfo and StreamingContext appropriately.

Any thoughts or suggestions would be much appreciated.
Thanks in advance!

Dan
 
G

Guest

use Request.InputStream:

FileStream log = new FileStream("C:\\dump.tmp",
FileMode.OpenOrCreate);
byte[] buffer = new byte[1024];
int c;
while ((c = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
{
log.Write(buffer, 0, c);
}
log.Close();



-- bruce (sqlwork.com)
 
M

manheim

Thanks! That looks like it will do the trick.
The one challenge is that I am also getting data through QueryString.
It looks like using InputStream will put all POST and GET data (and
presumably other Request data like Cookies) together into one file.
I assume that's what's happening since I can't open the jpg after I
save it out.

Is there a way to separate the POST data?

Dan

use Request.InputStream:

FileStream log = new FileStream("C:\\dump.tmp",
FileMode.OpenOrCreate);
byte[] buffer = new byte[1024];
int c;
while ((c = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
{
log.Write(buffer, 0, c);
}
log.Close();

-- bruce (sqlwork.com)

I have a page posting a raw jpg to me via HTTP POST. All reference
I've found is centered around retrieving POST data as name/value pairs
which will not work in this situation.
What I need to do is retrieve the raw POST data and save it as a
jpg.
Here is some php code that does the same thing for reference:
$jfh = fopen($jpeg_file, 'w') or die("can't open file");
fwrite($jfh, $GLOBALS['HTTP_RAW_POST_DATA']);
fclose($jfh);
I assume there is some way to access POST data as a stream and then
write that stream to a file, but it's not clear to me how. Perhaps I
need to use Request.Form.GetObjectData, but I'm not sure how to setup
SerializationInfo and StreamingContext appropriately.
Any thoughts or suggestions would be much appreciated.
Thanks in advance!
 
G

Guest

Consider using an HTTP Sniffer like Fiddler to examine the actual POST so you
can see how it is actually being sent.
--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com



Thanks! That looks like it will do the trick.
The one challenge is that I am also getting data through QueryString.
It looks like using InputStream will put all POST and GET data (and
presumably other Request data like Cookies) together into one file.
I assume that's what's happening since I can't open the jpg after I
save it out.

Is there a way to separate the POST data?

Dan

use Request.InputStream:

FileStream log = new FileStream("C:\\dump.tmp",
FileMode.OpenOrCreate);
byte[] buffer = new byte[1024];
int c;
while ((c = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
{
log.Write(buffer, 0, c);
}
log.Close();

-- bruce (sqlwork.com)

I have a page posting a raw jpg to me via HTTP POST. All reference
I've found is centered around retrieving POST data as name/value pairs
which will not work in this situation.
What I need to do is retrieve the raw POST data and save it as a
jpg.
Here is some php code that does the same thing for reference:
$jfh = fopen($jpeg_file, 'w') or die("can't open file");
fwrite($jfh, $GLOBALS['HTTP_RAW_POST_DATA']);
fclose($jfh);
I assume there is some way to access POST data as a stream and then
write that stream to a file, but it's not clear to me how. Perhaps I
need to use Request.Form.GetObjectData, but I'm not sure how to setup
SerializationInfo and StreamingContext appropriately.
Any thoughts or suggestions would be much appreciated.
Thanks in advance!
 
G

Guest

in the html payload, the cookie is in the header, and is just before the
postdata. the url parameters are actuallly on the same line as action
(GET/POST).

see the Request object, you can get the cookie, headers and querystring
(parsed/unparsed).

-- bruce (sqlwork.com)


Thanks! That looks like it will do the trick.
The one challenge is that I am also getting data through QueryString.
It looks like using InputStream will put all POST and GET data (and
presumably other Request data like Cookies) together into one file.
I assume that's what's happening since I can't open the jpg after I
save it out.

Is there a way to separate the POST data?

Dan

use Request.InputStream:

FileStream log = new FileStream("C:\\dump.tmp",
FileMode.OpenOrCreate);
byte[] buffer = new byte[1024];
int c;
while ((c = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
{
log.Write(buffer, 0, c);
}
log.Close();

-- bruce (sqlwork.com)

I have a page posting a raw jpg to me via HTTP POST. All reference
I've found is centered around retrieving POST data as name/value pairs
which will not work in this situation.
What I need to do is retrieve the raw POST data and save it as a
jpg.
Here is some php code that does the same thing for reference:
$jfh = fopen($jpeg_file, 'w') or die("can't open file");
fwrite($jfh, $GLOBALS['HTTP_RAW_POST_DATA']);
fclose($jfh);
I assume there is some way to access POST data as a stream and then
write that stream to a file, but it's not clear to me how. Perhaps I
need to use Request.Form.GetObjectData, but I'm not sure how to setup
SerializationInfo and StreamingContext appropriately.
Any thoughts or suggestions would be much appreciated.
Thanks in advance!
 
M

manheim

Thanks. Turned out there was an extra byte in their stream breaking
it, so it's all good. Request.InputStream got the raw POST data and
Request.QueryString still gave me the QS vars.
Thanks for all the help!

Consider using an HTTP Sniffer like Fiddler to examine the actual POST so you
can see how it is actually being sent.
--Peter
"Inside every large program, there is a small program trying to get out."http://www.eggheadcafe.comhttp://petesbloggerama.blogspot.comhttp://www.blogmetafinder.com

Thanks! That looks like it will do the trick.
The one challenge is that I am also getting data through QueryString.
It looks like using InputStream will put all POST and GET data (and
presumably other Request data like Cookies) together into one file.
I assume that's what's happening since I can't open the jpg after I
save it out.
Is there a way to separate the POST data?
use Request.InputStream:
FileStream log = new FileStream("C:\\dump.tmp",
FileMode.OpenOrCreate);
byte[] buffer = new byte[1024];
int c;
while ((c = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
{
log.Write(buffer, 0, c);
}
log.Close();
-- bruce (sqlwork.com)
:
I have a page posting a raw jpg to me via HTTP POST. All reference
I've found is centered around retrieving POST data as name/value pairs
which will not work in this situation.
What I need to do is retrieve the raw POST data and save it as a
jpg.
Here is some php code that does the same thing for reference:
$jfh = fopen($jpeg_file, 'w') or die("can't open file");
fwrite($jfh, $GLOBALS['HTTP_RAW_POST_DATA']);
fclose($jfh);
I assume there is some way to access POST data as a stream and then
write that stream to a file, but it's not clear to me how. Perhaps I
need to use Request.Form.GetObjectData, but I'm not sure how to setup
SerializationInfo and StreamingContext appropriately.
Any thoughts or suggestions would be much appreciated.
Thanks in advance!
Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top