'Content-Type' header 必须使用适当的 属性 或方法进行修改。参数名称:名称
The 'Content-Type' header must be modified using the appropriate property or method. Parameter name: name
您好,我正在使用 HttpWebRequest GET 方法调用 REST 服务。我收到错误消息:- ***'Content-Type' header 必须使用适当的 属性 或方法进行修改。参数名称:名称。***我从 Whosebug 中检查了所有与此问题相关的答案。
我的代码:-
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);
}
}
我也遇到了这个问题。但意识到问题在于您如何设置内容类型。
正确的设置方法是
request.ContentType = "application/json";
您好,我正在使用 HttpWebRequest GET 方法调用 REST 服务。我收到错误消息:- ***'Content-Type' header 必须使用适当的 属性 或方法进行修改。参数名称:名称。***我从 Whosebug 中检查了所有与此问题相关的答案。
我的代码:-
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);
}
}
我也遇到了这个问题。但意识到问题在于您如何设置内容类型。
正确的设置方法是
request.ContentType = "application/json";