media-type

ASP.NET WebAPI Supported Media Types per Method

可紊 提交于 2020-01-13 10:21:49
问题 Given a method in a controller: public class CustomerController : ApiController { [HttpGet] public CustomerDto GetById([FromUri] int id) { . . return customerDto } } Is there a way to specify supported Media Types with an attribute? For instance, CustomerDto is a complex class and will only serialize with JSON (application/json) not XML (application/xml) but could also accept PDF (application/pdf). Is there something like this: [HttpGet(Accepts.JSON, Accepts.PDF)] or [HttpGet][AcceptJSON]

Restrict accepted Media Types in ASP.NET Core Controller action

风格不统一 提交于 2020-01-11 08:38:27
问题 I have an ASP.NET Core Service that produces both JSON and XML responses. However, I like to restrict the accepted Media Type for only one action, so Swagger can only list application/json as a valid response content type . How can I achieve this in ASP.Net Core? Please, consider I am using ASP.Net Core (ASP.NET MVC 6), not ASP.NET WebAPI. UPDATE Ok, so I'll add the answer as part of the same question. Thanks to @Helen, I was able to add the required classes to achieve this in ASP.Net Core

What's the easiest and quickest way to get the MIME/Media/Content type of a given URL?

我与影子孤独终老i 提交于 2019-12-31 05:40:33
问题 So I'm going to transfer a file from a remote server to my server but before I transfer it I want to know what sort of file it is. If it's an HTML file I'll deal with it in a certain way, if it's a PDF file I'll deal with it in a different way, and if, for instance, it's an exe file, I don't want to transfer it at all. All I've got to go on is a URL. Now if that URL is explicit (i.e. http://example.com/file.pdf) it's not a problem, I can just check the file extension and we're sorted. However

Jersey REST WS Error: “Missing dependency for method… at parameter at index X”

巧了我就是萌 提交于 2019-12-29 06:16:13
问题 I am getting the following error: Apr 09, 2013 12:24:26 PM com.sun.jersey.spi.inject.Errors processErrorMessages SEVERE: The following errors and warnings have been detected with resource and/or provider classes: SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.package.ImportService.specifyLocalFile(java.lang.String,java.lang.String,java.lang.String,java.lang.String) at parameter at index 0 SEVERE: Missing dependency for method public javax.ws.rs.core.Response com

How can I customize HTTP 400 responses for parse errors?

做~自己de王妃 提交于 2019-12-21 15:16:12
问题 I've written a REST API service that requires that all responses be JSON. However, when the Go HTTP request parser encounters an error, it returns 400 as a plain text response without ever calling my handlers. Example: > curl -i -H 'Authorization: Basic hi there' 'http://localhost:8080/test' -v * Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 8080 (#0) > GET /test HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.54.0 > Accept: */* > Authorization: Basic hi > there > <

How can I customize HTTP 400 responses for parse errors?

倾然丶 夕夏残阳落幕 提交于 2019-12-21 15:15:25
问题 I've written a REST API service that requires that all responses be JSON. However, when the Go HTTP request parser encounters an error, it returns 400 as a plain text response without ever calling my handlers. Example: > curl -i -H 'Authorization: Basic hi there' 'http://localhost:8080/test' -v * Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 8080 (#0) > GET /test HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.54.0 > Accept: */* > Authorization: Basic hi > there > <

Correct use of Apache Tika MediaType

别等时光非礼了梦想. 提交于 2019-12-19 11:48:12
问题 I want to use APache Tika's MediaType class to compare mediaTypes. I first use Tika to detect the MediaType. Then I want to start an action according to the MediaType. So if the MediaType is from type XML I want to do some action, if it is a compressed file I want to start an other action. My problem is that there are many XML types, so how do I check if it is an XML using the MediaType ? Here is my previous (before Tika) implementation: if (contentType.contains("text/xml") || contentType

CSS media type: How to load CSS for mobile?

烈酒焚心 提交于 2019-12-17 15:57:18
问题 With this code: <link rel="stylesheet" type="text/css" href="media/css/mobile.css" media="handheld" /> <link rel="stylesheet" type="text/css" href="media/css/screen.css" media="screen" /> on my N78 the nokia's default browser and opera mini load screen.css instead of mobile.css . What am I missing? 回答1: Nokia N78 uses the S60 browser, which reads only "screen" stylesheets. It won't read the "handheld". It doesn't support media query. Instead of trying to type everything here, have a look at

URLDecoder: Illegal hex characters in escape (%) pattern for multipart data

≯℡__Kan透↙ 提交于 2019-12-13 03:45:14
问题 I am using multipart to fetch the pdf and object data from the service. I get the below error java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "PD" at java.net.URLDecoder.decode(URLDecoder.java:205) at org.springframework.http.converter.FormHttpMessageConverter.read(FormHttpMessageConverter.java:186) when invoking the service. SERVICE : @RequestMapping(value = "/getPDF", method = RequestMethod.GET,produces = MediaType.MULTIPART

Rest can MediaType.MULTIPART_FORM_DATA be used with @Produces

风格不统一 提交于 2019-12-11 17:41:29
问题 I have a rest service which produces the object of this format : FileDetailsObject{ byte[] data; String position_of_logo; String username; } Is there a way to accomplish this in rest? If it was just byte[] , I could use the Octet_Stream. But I need to return an object with a byte[]. I read about MediaType. Multipart_Form_Data but as far as I understand it seems to be associated with @Consumes where you can send it to a service post request. Any pointers would be helpful. Thanks 回答1: You can