Getting error message - The 'Accept' header must be modified using the appropriate property or method. i'm getting the response in the post man but not getting in the MVC controller i have one basic authentication api with below headers.while using adding accept headers in the request getting the error
Content-Type: application/vnd.onem2m-res+json;ty=4;
Accept: application/vnd.onem2m-res+json;
Cache-Control: no-cache
X-M2M-RI: 9900001
Authorization: Basic QzdBQUNFO
X-M2M-Origin: C7AACE9-25
code
WebRequest req = WebRequest.Create(@"url");
req.Method = "GET";
req.Headers["Authorization"] = "Basic " + "QzdBQUNFO";
req.ContentType = "application/vnd.onem2m-res+json";
req.Headers.Add("Accept", "application/vnd.onem2m-res+json;");
req.Headers["Cache-Control"] = "no-cache";
req.Headers["X-M2M-RI"] = "9900001";
req.Headers["X-M2M-Origin"] = "C7AACE9-25";
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
var encoding = resp.CharacterSet == "" ? Encoding.UTF8 : Encoding.GetEncoding(resp.CharacterSet);
The Accept request HTTP header indicates which content types, expressed as MIME types, the client is able to understand. The server uses content negotiation to select one of the proposals and informs the client of the choice with the Content-Type response header.
Servers may ignore the Accept header. If you're not returning anything in your response, it's kind of meaningless. It's up to you to decide whether you want to reject requests with Accept headers or not.
WebRequest req = WebRequest.Create(@"url");
req.Method = "GET";
req.Headers["Authorization"] = "Basic " + "QzdBQUNFO";
req.ContentType = "application/vnd.onem2m-res+json";
req.Accept = "application/vnd.onem2m-res+json";
req.Headers["Cache-Control"] = "no-cache";
req.Headers["X-M2M-RI"] = "9900001";
req.Headers["X-M2M-Origin"] = "C7AACE9-25";
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
var encoding = resp.CharacterSet == "" ? Encoding.UTF8 : Encoding.GetEncoding(resp.CharacterSet);
microsoft docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With