Эквивалентный из WebClient.NET и HttpWebRequest в Java?

Это зависит от Вашей цели. Если Вы программируете для сети, избегаете indexOf, она не поддерживается Internet  Explorer  6 (партия их все еще используемый!), или делают условное использование:

if (yourArray.indexOf !== undefined) result = yourArray.indexOf(target);
else result = customSlowerSearch(yourArray, target);

indexOf, вероятно, кодируется в собственном коде, таким образом, это быстрее, чем что-нибудь, что можно сделать в JavaScript (кроме двоичного поиска / дихотомия, если массив является соответствующим).Примечание: это - вопрос вкуса, но я сделал бы return false; в конце Вашей стандартной программы, для возврата истинной булевской переменной...

9
задан dreftymac 22 March 2019 в 23:16
поделиться

3 ответа

HttpURLConnection is Java's equivalent of HttpWebRequest.

URL iurl = new URL(url);
HttpURLConnection uc = (HttpURLConnection)iurl.openConnection();
uc.connect();
if (uc.getContentType().equalsIgnoreCase("image/jpeg"))
{
  result = true;
}
11
ответ дан 4 December 2019 в 10:33
поделиться

html-модуль для меня. я могу имитировать javascript (в определенной степени)

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

Apache HTTPClient has equivalent functionality, though the APIs are not exactly the same. Oakland Software has a table comparing their commercial product with various alternatives, including the Apache product. Apache's own opinion of the built-in HttpUrlConnection (quoted from the above linked-to page) is:

The jdk has the HttpUrlConnection which is limited and in many ways flawed.

Here's a link to the HTTPClient tutorial.

7
ответ дан 4 December 2019 в 10:33
поделиться
Другие вопросы по тегам:

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