1

初心者からの簡単な質問です。Aptana Studio 3 を使用していて、W3C 検証を使用しているときにエラー メッセージが表示された人はいますか?

Status: 403 Forbidden Vary: Referer Content-type: text/html

Markup Validation Service

Sorry! This document can not be checked.
No User-Agent header found!

簡単な Google は、他のエディター/IDE ユーザーが、HTML-Kit などの同様のことを経験していることを示唆しています。W3C 検証サービスは、ブラウザーによって直接提供されるユーザー エージェント文字列を期待しているように見えますが、おそらくエディター/IDE によってではありませんか?

別の検証サービスを使用するか、ブラウザー経由でコードをチェックすることで、問題を回避する方法があることを知っています。フラグを立てると思っただけです。

4

2 に答える 2

2

これについては、Aptana Studio プロジェクトに修正を提出しました。この修正には、w3c に送信される投稿に http ユーザー エージェントを追加することが含まれます。

w3c_validation.rb

w3c_validation.rb ファイル内のテキストを以下のテキストに置き換えます。パスの例: C:\Users\user\AppData\Local\Aptana Studio 3\configuration\org.eclipse.osgi\bundles\101\1.cp\bundles\html.ruble\commands\w3c_validation.rb

require 'ruble'

command t(:validate_syntax) do |cmd|
  cmd.key_binding = 'CONTROL+M2+V'
  cmd.scope = 'text.html'
  cmd.output = :show_as_html
  cmd.input = :document
  cmd.invoke do |context|
    $KCODE = 'U'
    page = $stdin.read
    page.gsub!(/<\?(php|=).*?\?>|<%.*?%>/m, '')

    w3c_url = 'http://validator.w3.org/check'

    require 'net/http'
    require 'uri'

#fix for w3c blocking http requests without a user-agent
#changed the way the http post is sent to w3c so that it includes a user-agent

uri = URI(w3c_url)
req = Net::HTTP::Post.new(uri.path)
req.set_form_data({'ss' => "1", 'fragment' => page})
req['User-Agent'] = 'Aptana'

response = Net::HTTP.start(uri.host, uri.port) do |http|
  http.request(req)
end
    status = response['x-w3c-validator-status']

    content = response.body
    content = content.gsub(/<\/title>/, '\&<base href="http://validator.w3.org/">')
    # content.gsub!(/Line (\d+),? Column (\d+)/i) do
    # # FIXME These links won't work for us!
    # "<a href='txmt://open?line=#\$1&column=#{\$2.to_i + 1}'>#\$&</a>"
    # end
    content
  end
end
于 2013-07-24T13:18:18.010 に答える