【发布时间】:2012-10-30 13:37:36
【问题描述】:
我必须在给定的 URL 中发布 JSON 数据 我的 JSON 的样子
{
"trip_title":"My Hotel Booking",
"traveler_info":{
"first_name":"Edward",
"middle_name":"",
"last_name":"Cullen",
"phone":{
"country_code":"1",
"area_code":"425",
"number":"6795089"
},
"email":"asdv@gmail.com"
},
"billing_info":{
"credit_card":{
"card_number":"47135821",
"card_type":"Visa",
"card_security_code":"123",
"expiration_month":"09",
"expiration_year":"2017"
},
"first_name":"Edward",
"last_name":"Cullen",
"billing_address":{
"street1":"Expedia Inc",
"street2":"108th Ave NE",
"suite":"333",
"city":"Bellevue",
"state":"WA",
"country":"USA",
"zipcode":"98004"
},
"phone":{
"country_code":"1",
"area_code":"425",
"number":"782"
}
},
"marketing_code":""
}
还有我的功能
string message = "URL";
_body="JSON DATA";
HttpWebRequest request = HttpWebRequest.Create(message) as HttpWebRequest;
if (!string.IsNullOrEmpty(_body))
{
request.ContentType = "text/json";
request.Method = "POST";
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(_body);
streamWriter.Flush();
streamWriter.Close();
}
}
using (HttpWebResponse webresponse = request.GetResponse() as HttpWebResponse)
{
using (StreamReader reader = new StreamReader(webresponse.GetResponseStream()))
{
string response = reader.ReadToEnd();
}
}
当我发布它时;我收到一个错误
“远程服务器返回错误:(415) Unsupported Media Type。”
任何人都知道它;我哪里弄错了?
【问题讨论】:
-
您解决了这个问题吗?我遇到了一个非常相似的问题that I posted about here
-
我通过将信封命名空间从“schemas.xmlsoap.org/soap/envelope”更改为“w3.org/2003/05/soap-envelope”解决了这个错误...
标签: c# json http post httpwebrequest