J
JoeB
hi,
Im trying to send data (raw bytes) to a web server. I cannot figure out how
to do it. I need the data to be read by PHP which i have already written.
The data must be post data.
I also send some variables to the web server, which i can retreive, but the
raw data disapears.
Here is my sending code (error checking removed):
--------
string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
string sRequestUrl = this.sUrl + "?key=12345";
HttpWebRequest webrequest = CreateWebRequest( sRequestUrl );
webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
webrequest.Method = "POST";
webrequest.AllowWriteStreamBuffering = false;
// Build up the post message header
StringBuilder sb = new StringBuilder();
sb.Append("--" + boundary + "\r\n");
sb.Append("Content-Type: text/plain; name=\"data\"");
sb.Append("Content-Type: application/octet-stream");
sb.Append("\r\n\r\n");
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sb.ToString());
byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary +
"\r\n");
// Read file data.
byte[] buffer = new Byte[ this.iUploadBufferSize ];
long lBytesReadFromFile = fs.Read(buffer, (int)lOffset, buffer.Length);
// set request length.
webrequest.ContentLength = postHeaderBytes.Length + lBytesReadFromFile +
boundaryBytes.Length;
Stream requestStream = null;
requestStream = webrequest.GetRequestStream();
// Write out our post header
requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
// Write out the file contents
requestStream.Write( buffer, 0, (int)lBytesReadFromFile );
// Write out the trailing boundary
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
requestStream.Flush();
requestStream.Close();
--------
please help!!
Joe
Im trying to send data (raw bytes) to a web server. I cannot figure out how
to do it. I need the data to be read by PHP which i have already written.
The data must be post data.
I also send some variables to the web server, which i can retreive, but the
raw data disapears.
Here is my sending code (error checking removed):
--------
string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
string sRequestUrl = this.sUrl + "?key=12345";
HttpWebRequest webrequest = CreateWebRequest( sRequestUrl );
webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
webrequest.Method = "POST";
webrequest.AllowWriteStreamBuffering = false;
// Build up the post message header
StringBuilder sb = new StringBuilder();
sb.Append("--" + boundary + "\r\n");
sb.Append("Content-Type: text/plain; name=\"data\"");
sb.Append("Content-Type: application/octet-stream");
sb.Append("\r\n\r\n");
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sb.ToString());
byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary +
"\r\n");
// Read file data.
byte[] buffer = new Byte[ this.iUploadBufferSize ];
long lBytesReadFromFile = fs.Read(buffer, (int)lOffset, buffer.Length);
// set request length.
webrequest.ContentLength = postHeaderBytes.Length + lBytesReadFromFile +
boundaryBytes.Length;
Stream requestStream = null;
requestStream = webrequest.GetRequestStream();
// Write out our post header
requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
// Write out the file contents
requestStream.Write( buffer, 0, (int)lBytesReadFromFile );
// Write out the trailing boundary
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
requestStream.Flush();
requestStream.Close();
--------
please help!!
Joe