RestSharp मुझे पोस्ट अनुरोध के लिए सामग्री-प्रकार को ओवरराइड करने की अनुमति नहीं देता है। मैंने here को प्राप्त करने के लिए दिशानिर्देशों का पालन नहीं किया है। मैंने अनुरोध के माध्यम से हेडर सामग्री प्रकार मैन्युअल रूप से एप्लिकेशन/जेसन को सेट करने का भी प्रयास किया है। AddHeaders ("content-type", "application/json");RestSharp डिफ़ॉल्ट सामग्री के लिए सामग्री-प्रकार/x-www-form-urlencoded पर पोस्ट
अनुरोध निष्पादन के उदाहरण:
private IRestResponse ExecuteRequest<T>(string resource, Method method, T model)
{
var client = CreateRestClient();
var request = new RestRequest(resource, method)
{
RequestFormat = DataFormat.Json
};
var json = JsonConvert.SerializeObject(model);
request.AddHeader("Accept", "application/json");
request.AddHeader("User-Agent", "Fiddler");
request.Parameters.Clear();
request.AddParameter("auth_token", _apiKey);
request.AddParameter("application/json", json, ParameteType.RequestBody);
return client.Execute(request);
}
प्रतिक्रिया त्रुटि संदेश:
{
"error": {
"code": 400,
"message": "The request requires a properly encoded body with the 'content-type' header set to '['application/json']",
"type": "Bad Request" }
}
फ़िडलर अनुरोध कच्चे डेटा:
POST **omitted** HTTP/1.1
Accept: application/json, application/xml, text/json, text/x-json,text/javascript, text/xml
User-Agent: RestSharp/105.0.1.0
Content-Type: application/x-www-form-urlencoded
Host: **omitted**
Content-Length: 51
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
आप देख सकते हैं, अनुरोध सामग्री- प्रकार अभी भी आवेदन/एक्स-www-form-urlencoded है। कोई विचार? (अग्रिम धन्यवाद)
धन्यवाद, यह मेरे लिए काम करता है। यहां महत्वपूर्ण बदलाव यह है कि मेरे लिए यह किया गया था कि आपने अनुरोध कैसे किया .addParameter()। –