Канонический Почтовый индекс HTTP?

Короткий ответ:

Помещенный это в Ваш главный тег, чтобы сказать браузер, что Ваша страница работает в IE 8:

<meta http-equiv="X-UA-Compatible" content="IE=8" />

Также согласно комментарию Jon Hadleys, для обеспечения последнего (не только IE8) механизм визуализации используется, Вы могли использовать следующее:

<meta http-equiv="X-UA-Compatible" content="IE=edge">
15
задан John Saunders 19 February 2013 в 01:54
поделиться

3 ответа

I believe that the simple version of this would be

var client = new WebClient();
return client.UploadString(url, data);

The System.Net.WebClient class has other useful methods that let you download or upload strings or a file, or bytes.

Unfortunately there are (quite often) situations where you have to do more work. The above for example doesn't take care of situations where you need to authenticate against a proxy server (although it will use the default proxy configuration for IE).

Also the WebClient doesn't support uploading of multiple files or setting (some specific) headers and sometimes you will have to go deeper and use the

System.Web.HttpWebRequest and System.Net.HttpWebResponse instead.

10
ответ дан 1 December 2019 в 04:41
поделиться

Как говорили другие, WebClient.UploadString (или UploadData )

Однако встроенный WebClient имеет серьезный недостаток: у вас почти нет контроля над WebRequest , который используется за кулисами (файлы cookie, аутентификация , пользовательские заголовки ...). Простой способ решить эту проблему - создать собственный WebClient и переопределить метод GetWebRequest . Затем вы можете настроить запрос перед его отправкой (вы можете сделать то же самое для ответа, переопределив GetWebResponse ). Вот пример веб-клиента , поддерживающего файлы cookie . Это'

3
ответ дан 1 December 2019 в 04:41
поделиться

Сравните: с

// create a client object
using(System.Net.WebClient client = new System.Net.WebClient()) {
    // performs an HTTP POST
    client.UploadString(url, xml);  

}

по

string HttpPost (string uri, string parameters)
{ 
   // parameters: name1=value1&name2=value2 
   WebRequest webRequest = WebRequest.Create (uri);
   webRequest.ContentType = "application/x-www-form-urlencoded";
   webRequest.Method = "POST";
   byte[] bytes = Encoding.ASCII.GetBytes (parameters);
   Stream os = null;
   try
   { // send the Post
      webRequest.ContentLength = bytes.Length;   //Count bytes to send
      os = webRequest.GetRequestStream();
      os.Write (bytes, 0, bytes.Length);         //Send it
   }
   catch (WebException ex)
   {
      MessageBox.Show ( ex.Message, "HttpPost: Request error", 
         MessageBoxButtons.OK, MessageBoxIcon.Error );
   }
   finally
   {
      if (os != null)
      {
         os.Close();
      }
   }

   try
   { // get the response
      WebResponse webResponse = webRequest.GetResponse();
      if (webResponse == null) 
         { return null; }
      StreamReader sr = new StreamReader (webResponse.GetResponseStream());
      return sr.ReadToEnd ().Trim ();
   }
   catch (WebException ex)
   {
      MessageBox.Show ( ex.Message, "HttpPost: Response error", 
         MessageBoxButtons.OK, MessageBoxIcon.Error );
   }
   return null;
} // end HttpPost 

Почему люди используют / пишут последнее?

0
ответ дан 1 December 2019 в 04:41
поделиться
Другие вопросы по тегам:

Похожие вопросы: