开发者

http webrequest content type null

is it necessary to mention content-type in http header while uploading the file. i tried using c#. i had set it "image/png" while uploading a pdf file and when i downloaded the uploaded file, the pdf file was perfect. it didn't get corrupted.

so what is the role of specifying content-type in http header. can it be null or any other开发者_运维问答 wrong value.

because the application that i am making, user will just give the file and and i just need to upload it.

any help highly appreciated. thanks in advance.


Weird that nobody answered this question.

You should always set the content-type, some software (servers) may break when it's omitted.

You could give it any value that the target system can handle.

Since you can easily fake http request, you can also fake the headers. So your target system (in this case an upload processor) should only accept content-type values it's able to handle and you MUST validate if the given content-type actually matches the data that is send in the body (the uploaded file itself). You can never trust the content-type value, until you validate it somehow. As a PHP developer I always check any file upload against a mime-type validator to be sure I got what I expected. For example I use getimagesize() to detect whether it's an image or not and if it is to get it's file format type (PNG).

Since both PNG and PDF files are binary file formats your upload succeeded. This is because you coded it that way or the target system falls back on default settings or does some checking for itself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜