Accessing the exact data sent using WebClient.UploadData on the server

岁酱吖の 提交于 2019-12-12 17:43:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!