0

URLはこちら

http://192.168.1.2:1218/?name=verify_code_string_queue&opt=get&auth=verify_code_string_queue

文字列または SQS_GET_END のようなステータス コードを返します。

URL が文字列を返すとき、またはブロックし続けるときに、ループを中断する必要があります。

これが私のコードです

require 'net/http'
require 'open-uri'
loop do
  codeText = open("http://192.168.1.2:1218/?name=verify_code_string_queue&opt=get&auth=verify_code_string_queue") do |repo|
    repo.read
  end
  if codeText != "SQS_GET_END"
    break
  end
end

しかし、それは機能しません。出力は要求されたアドレスを割り当てることができません - connect(2) (Errno::EADDRNOTAVAIL)。解決方法を教えてください、よろしくお願いします

4

1 に答える 1

0

問題は、短時間にあまりにも多くのリクエストを行っていることです。これにより、Errno::EADDRNOTAVAILエラーが発生します。sleepループ内に a を追加して、作成するリクエストの数を制限できます。

このようなもの:

require 'net/http'
require 'open-uri'
loop do
  codeText = open("http://192.168.1.2:1218/?name=verify_code_string_queue&opt=get&auth=verify_code_string_queue") do |repo|
    repo.read
  end
  if codeText != "SQS_GET_END"
    break
  end
  sleep 1 # <= sleep for one second
end
于 2012-12-28T10:44:02.527 に答える