相关疑难解决方法(0)

HTTP"Content-Type"标头的所有可能值是什么?

我必须在将Content-Type标头值传递给HTTP请求之前验证它.

是否有针对所有可能值的特定列表Content-Type

否则,有没有办法在HTTP请求中使用它之前验证内容类型?

content-type http http-headers http-request

233
推荐指数
2
解决办法
30万
查看次数

.NET框架中的"application/json"常量

我刚刚为我的一个类中的"application/json"内容类型声明了一个常量.

public const string JsonContentType = "application/json";
Run Code Online (Sandbox Code Playgroud)

我不确定这是一个好习惯.

.NET框架是否具有"application/json"的预定义const?

.net c# asp.net-mvc content-type

64
推荐指数
3
解决办法
3万
查看次数

在HttpWebResponse("text/plain","application/octet-stream"等)上是否有ContentType属性的枚举?

我能找到的最接近的东西是,System.Net.Mime.MediaTypeNames但似乎没有一切(如json),因为它似乎更专注于电子邮件附件.

content-type httpwebresponse mime-types

48
推荐指数
2
解决办法
2万
查看次数

调用Web API 2端点时,HTTP 415不支持的媒体类型错误

我有一个现有的Web API 2服务,需要修改其中一个方法以将自定义对象作为另一个参数,目前该方法有一个参数,它是来自URL的简单字符串.将自定义对象添加为参数后,从.NET Windows应用程序调用服务时,我现在收到415不支持的媒体类型错误.有趣的是,我可以使用javascript和jquery ajax方法成功调用此方法.

Web API 2服务方法如下所示:

<HttpPost>
<HttpGet>
<Route("{view}")>
Public Function GetResultsWithView(view As String, pPaging As Paging) As HttpResponseMessage
   Dim resp As New HttpResponseMessage
   Dim lstrFetchXml As String = String.Empty
   Dim lstrResults As String = String.Empty

   Try
      '... do some work here to generate xml string for the response
      '// write xml results to response
      resp.Content = New StringContent(lstrResults)
      resp.Content.Headers.ContentType.MediaType = "text/xml"
      resp.Headers.Add("Status-Message", "Query executed successfully")
      resp.StatusCode = HttpStatusCode.OK
   Catch ex As Exception
      resp.StatusCode = HttpStatusCode.InternalServerError
      resp.Headers.Add("Status-Message", String.Format("Error …
Run Code Online (Sandbox Code Playgroud)

vb.net json asp.net-web-api http-status-code-415 asp.net-web-api2

31
推荐指数
4
解决办法
13万
查看次数

ASP.NET vNext如何处理config.json中的缓存,压缩和MimeMap?

在以前的版本中,可以使用类似下面的代码在Web.Config文件中添加和调整所有这些设置:

<staticContent>
  <mimeMap fileExtension=".webp" mimeType="image/webp" />
  <!-- Caching -->
  <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="96:00:00" />
</staticContent>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/javascript" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/javascript" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
Run Code Online (Sandbox Code Playgroud)

但是,由于Web.Config不再出现在ASP.NET vNext中,你如何调整这样的设置?我搜索过网络ASP.NET Github仓库,但没有遇到任何问题 - 任何想法?

compression asp.net asp.net-mvc caching asp.net-core

7
推荐指数
1
解决办法
1370
查看次数

C#Mime Types类

我想在我的代码中保存Mime类型.现在我用来做这个:

string mYMimeType = "text/plain";
Run Code Online (Sandbox Code Playgroud)

有没有办法将它保存在(已经存在的)标准专用类中?就像是...

Http.MimeTypes myMimeType = Http.MimeTypes.TextPlain;
Run Code Online (Sandbox Code Playgroud)

.net c# mime-types

7
推荐指数
1
解决办法
3483
查看次数