Как исправить: удаленный сервер вернул ошибку: (400) Плохой запросC#

Место общения программистов C#
Anonymous
Как исправить: удаленный сервер вернул ошибку: (400) Плохой запрос

Сообщение Anonymous »

Я пытаюсь исправить эту ошибку, я знаю, что есть еще один подобный вопросы с той же ошибкой, но строка: request.contentlength = 0; < /code> это не исправляет мое исключение.public ActionResult Index()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
string serviceUrl = string.Format(@"http://localhost:61940/Service1.svc/GetPlayer/");

HttpWebRequest request = (HttpWebRequest) WebRequest.Create(serviceUrl);
request.Method = "POST";
request.ContentType = @"application/json; charset=utf-8";
request.ContentLength = 0;

HttpWebResponse response = (HttpWebResponse) request.GetResponse();
Stream stream = request.GetRequestStream();
StreamWriter reader = new StreamWriter(stream);
}
< /code>

И это мой web.config < /strong> < /p>



































< /code>

любая помощь? Спасибо за ответы. < /strong> < /p>

И это мой контракт < /strong> < /p>

[ServiceContract]
public interface IService1
{

[OperationContract]
[WebInvoke(UriTemplate = "GetPlayer", ResponseFormat = WebMessageFormat.Json)]
Player GetPlayer();

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

// TODO: Add your service operations here
}


Подробнее здесь: https://stackoverflow.com/questions/381 ... ad-request

Вернуться в «C#»