The problem arises:
Today in the provision of API interface to the customer, the customer made a request, there is an interface to return the voice file URL address needs to be validated, here refers to the valid refers to the request of the URL can directly download the voice file, the reverse is considered invalid.
Let's take a look at the URL address of two request voice files:
Valid: http://xxx.xxx.xxx.xxx:60000/GetRecord.ashx?cid=1586887989, after accessing the page output, as shown in:
Invalid: http://xxx.xxx.xxx.xxx:60000/GetRecord.ashx?cid=1768218725
Obviously, due to the different parameters of the CID, resulting in some requests will not get the corresponding file output, then how to quickly determine the URL is valid and available to download it?
Solution Ideas:
1. Using the Syste.Net.HttpWebRequest class for HTTP requests, and obtain the return type after the request, do not need to stream to read the server-side file content into memory, only need to get the server-side request after the response of the file type, if the return is a WAV file, ContentType = "Audio/wav", if HTML page, contenttype= "text/html".
2. Match the file type of the response against the MIME content type table.
3. The following list of commonly used MIME (multipurpose Internet Mail Extensions) content type tables
Extended Name |
Type/Sub-type |
|
Application/octet-stream |
323 |
text/h323 |
Acx |
Application/internet-property-stream |
Ai |
Application/postscript |
Aif |
Audio/x-aiff |
Aifc |
Audio/x-aiff |
Aiff |
Audio/x-aiff |
Asf |
video/x-ms-asf |
Asr |
video/x-ms-asf |
asx |
video/x-ms-asf |
Au |
Audio/basic |
Avi |
Video/x-msvideo |
Axs |
Application/olescript |
Bas |
Text/plain |
Bcpio |
Application/x-bcpio |
Bin |
Application/octet-stream |
Bmp |
Image/bmp |
C |
Text/plain |
Cat |
Application/vnd.ms-pkiseccat |
Cdf |
Application/x-cdf |
Cer |
Application/x-x509-ca-cert |
Class |
Application/octet-stream |
Clp |
Application/x-msclip |
Cmx |
Image/x-cmx |
Cod |
Image/cis-cod |
Cpio |
Application/x-cpio |
Crd |
Application/x-mscardfile |
Ar. |
Application/pkix-crl |
Crt |
Application/x-x509-ca-cert |
Csh |
Application/x-csh |
As1 |
Text/css |
Dcr |
Application/x-director |
Der |
Application/x-x509-ca-cert |
Dir |
Application/x-director |
Dll |
Application/x-msdownload |
Dms |
Application/octet-stream |
Doc |
Application/msword |
Dot |
Application/msword |
Dvi |
Application/x-dvi |
DxR |
Application/x-director |
Eps |
Application/postscript |
Etx |
Text/x-setext |
Evy |
Application/envoy |
Exe |
Application/octet-stream |
Fif |
Application/fractals |
Flr |
X-world/x-vrml |
Gif |
Image/gif |
Gtar |
Application/x-gtar |
Gz |
Application/x-gzip |
H |
Text/plain |
Hdf |
Application/x-hdf |
Hlp |
Application/winhlp |
Hqx |
application/mac-binhex40 |
Hta |
Application/hta |
Htc |
Text/x-component |
Htm |
Text/html |
Html |
Text/html |
Htt |
Text/webviewhtml |
Ico |
Image/x-icon |
Ief |
Image/ief |
Iii |
Application/x-iphone |
Ins |
Application/x-internet-signup |
Isp |
Application/x-internet-signup |
Jfif |
Image/pipeg |
Jpe |
Image/jpeg |
Jpeg |
Image/jpeg |
Jpg |
Image/jpeg |
Js |
Application/x-javascript |
Latex |
Application/x-latex |
Lha |
Application/octet-stream |
Lsf |
video/x-la-asf |
LSx |
video/x-la-asf |
Lzh |
Application/octet-stream |
M13 |
Application/x-msmediaview |
M14 |
Application/x-msmediaview |
M3u |
Audio/x-mpegurl |
Mans |
Application/x-troff-man |
Mdb |
Application/x-msaccess |
Me |
Application/x-troff-me |
Mht |
message/rfc822 |
Mhtml |
message/rfc822 |
Mid |
Audio/mid |
On |
Application/x-msmoney |
mov |
Video/quicktime |
Movie |
Video/x-sgi-movie |
Mp2 |
Video/mpeg |
mp3 |
Audio/mpeg |
MPa |
Video/mpeg |
Mpe |
Video/mpeg |
Mpeg |
Video/mpeg |
Mpg |
Video/mpeg |
Mpp |
Application/vnd.ms-project |
Mpv2 |
Video/mpeg |
Ms |
Application/x-troff-ms |
Mvb |
Application/x-msmediaview |
Nws |
message/rfc822 |
Oda |
Application/oda |
P10 |
Application/pkcs10 |
P12 |
Application/x-pkcs12 |
p7b |
Application/x-pkcs7-certificates |
p7c |
Application/x-pkcs7-mime |
p7m |
Application/x-pkcs7-mime |
p7r |
Application/x-pkcs7-certreqresp |
P7s |
Application/x-pkcs7-signature |
Pbm |
Image/x-portable-bitmap |
Pdf |
Application/pdf |
pFX |
Application/x-pkcs12 |
Pgm |
Image/x-portable-graymap |
Pko |
Application/ynd.ms-pkipko |
Pma |
Application/x-perfmon |
Pmc |
Application/x-perfmon |
Pml |
Application/x-perfmon |
Pmr |
Application/x-perfmon |
Pmw |
Application/x-perfmon |
Pnm |
Image/x-portable-anymap |
Pot |
Application/vnd.ms-powerpoint |
Ppm |
Image/x-portable-pixmap |
Pps |
Application/vnd.ms-powerpoint |
Ppt |
Application/vnd.ms-powerpoint |
Prf |
Application/pics-rules |
Ps |
Application/postscript |
Pub |
Application/x-mspublisher |
Qt |
Video/quicktime |
Ra |
Audio/x-pn-realaudio |
Ram |
Audio/x-pn-realaudio |
Ras |
Image/x-cmu-raster |
Rgb |
Image/x-rgb |
Rmi |
Audio/mid |
Roff |
Application/x-troff |
Rtf |
Application/rtf |
Rtx |
Text/richtext |
Scd |
Application/x-msschedule |
Sct |
Text/scriptlet |
Setpay |
Application/set-payment-initiation |
SetReg |
Application/set-registration-initiation |
Sh |
Application/x-sh |
Shar |
Application/x-shar |
Sit |
Application/x-stuffit |
Snd |
Audio/basic |
Spc |
Application/x-pkcs7-certificates |
Spl |
Application/futuresplash |
Src |
Application/x-wais-source |
Sst |
Application/vnd.ms-pkicertstore |
Stl |
Application/vnd.ms-pkistl |
Stm |
Text/html |
Svg |
Image/svg+xml |
Sv4cpio |
Application/x-sv4cpio |
Sv4crc |
Application/x-sv4crc |
Swf |
Application/x-shockwave-flash |
T |
Application/x-troff |
Tar |
Application/x-tar |
Tcl |
Application/x-tcl |
re> |
Application/x-tex |
Texi |
Application/x-texinfo |
Texinfo |
Application/x-texinfo |
Tgz |
Application/x-compressed |
Tif |
Image/tiff |
Tiff |
Image/tiff |
Tr |
Application/x-troff |
Trm |
Application/x-msterminal |
Rs0 |
Text/tab-separated-values |
Txt |
Text/plain |
Uls |
Text/iuls |
Ustar |
Application/x-ustar |
vcf |
Text/x-vcard |
Vrml |
X-world/x-vrml |
Wav |
Audio/x-wav |
Wcm |
Application/vnd.ms-works |
Wdb |
Application/vnd.ms-works |
Wks |
Application/vnd.ms-works |
Wmf |
Application/x-msmetafile |
Wps |
Application/vnd.ms-works |
Wri |
Application/x-mswrite |
Wrl |
X-world/x-vrml |
Wrz |
X-world/x-vrml |
Xaf |
X-world/x-vrml |
Xbm |
Image/x-xbitmap |
Xla |
Application/vnd.ms-excel |
Xlc |
Application/vnd.ms-excel |
Xlm |
Application/vnd.ms-excel |
Xls |
Application/vnd.ms-excel |
Xlt |
Application/vnd.ms-excel |
Xlw |
Application/vnd.ms-excel |
Xof |
X-world/x-vrml |
xpm |
Image/x-xpixmap |
Xwd |
Image/x-xwindowdump |
Z |
Application/x-compress |
Zip |
Application/zip |