Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The 'Content-Type' header must be modified using the appropriate property or method. Parameter name: name

Hi I am using HttpWebRequest GET method to call a REST service. I am getting error :- ***'Content-Type' header must be modified using the appropriate property or method. Parameter name: name.***i checked all answer related this issue from stackoverflow.

My Code:-

    using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        Getvalue(TextBox1.Text,TextBox2.Text,TextBox3.Text);
    }

    private void Getvalue(string text1, string text2, string text3)
    {

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";
        request.KeepAlive = true;
        request.ContentType = "appication/json";
        request.Headers.Add("Content-Type", "appication/json");
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        string myResponse = "";
 using (System.IO.StreamReader sr = new system.IO.StreamReader(response.GetResponseStream()))
        {
            myResponse = sr.ReadToEnd();
        }
        Response.Write(myResponse);

}
}
like image 812
Anuj Avatar asked Jul 13 '17 09:07

Anuj


Video Answer


1 Answers

I too ended up with this problem. But realized the issue is with how you setting the content type.

The proper way to set is

request.ContentType = "application/json";
like image 149
coolcake Avatar answered Oct 12 '22 22:10

coolcake