问题
Newbie question: I'm sending a large text string in the form of a byte array using the WebClient.UploadData method to a web site but I'm not sure exactly where to retrieve that data from on the server. I've read posts that say it is in the request object which I already know but how exactly do I retrieve the specific byte array I sent like in the following c# pseudo code:
byte[] dataSent = request.GettheByteArrayISentFromWebClientUploadDataMethod;
I understand that it may not be as simple as this and that I may need to do some other processing but can anyone post a code snippet that shows how I can get at the byte array that was sent?
Mucho Thank-you
回答1:
Try reading it from the request stream Request.InputStream:
var bytes = new byte[request.InputStream.Length];
Request.InputStream.Read(bytes, 0, bytes.Length);
If you are sending key/value pairs then you could use the UploadValues method and read them simply as request paraneters:
string value = Request["someKey"];
来源:https://stackoverflow.com/questions/3267078/accessing-the-exact-data-sent-using-webclient-uploaddata-on-the-server