- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
在我们的 Rails 应用中,我们有一个 Controller Action ,它打开一个外部 URL,并将它作为 JSON 返回给我们的前端使用。
今天,我收到以下错误:
Errno::EAFNOSUPPORT:协议(protocol)不支持地址族 - socket(2)
我们的开发人员建议,如果地址同时返回 IPv6 响应和 IPv4 响应,这就是错误。我们不支持 IPv6,所以这可以解释它。
这是触发请求的方法:
def medline_response
open("http://apps.nlm.nih.gov/medlineplus/services/mpconnect_service.cfm?mainSearchCriteria.v.cs=#{codesys}&mainSearchCriteria.v.c=#{code}")
end
事实上,来自该服务器主机的响应:
$ host apps.nlm.nih.gov
apps.nlm.nih.gov is an alias for apps.wip.nlm.nih.gov.
apps.wip.nlm.nih.gov has address 130.14.16.117
apps.wip.nlm.nih.gov has IPv6 address 2607:f220:41e:1016::117
docs for open-uri 没有说明 IP 版本。是否有一个参数可以传递给 open
方法以强制它读取 IPv4,或者有其他方法来处理这个问题?
当我尝试从控制台打开 google 时,我得到了这个:
[18] pry(main)> require 'open-uri'
=> false
[19] pry(main)> open 'http://google.com'
=> #<File:/var/folders/hq/7_rgkt4565q728y91dtqzs2r2wxb1y/T/open-uri20130913-50258-1af4zhv>
所以看起来 IPv6 地址不是问题。
$ ruby -v
ruby 1.9.3p385 (2013-02-06 revision 39114) [x86_64-darwin11.4.2]
OS X 10.7.5
这是每个人都喜欢的错误类型:间歇性错误。下面是我在 open-uri
对象上调用 read 时发生的情况。我在本地和所有 3 个应用服务器上都得到了相同的输出。
[22] pry(main)> open("http://apps.nlm.nih.gov/medlineplus/services/mpconnect_service.cfm?mainSearchCriteria.v.cs=2.16.840.1.113883.6.103&mainSearchCriteria.v.c=238.4").read
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<feed xml:base=\"http://apps.nlm.nih.gov/medlineplus/services/\" xml:lang=\"en\" xmlns=\"http://www.w3.org/2005/Atom\" xmlns:v3=\"urn:hl7-org:v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><title type=\"text\">MedlinePlus Connect</title><subtitle type=\"text\">MedlinePlus Connect results for ICD-9-CM 238.4</subtitle><author><name>U.S. National Library of Medicine</name><uri>http://www.nlm.nih.gov</uri></author><updated type=\"text\">2013-09-13T12:09:48Z</updated><category scheme=\"REDS_MT010001UV\" term=\"MATCHED\"><v3:mainSearchCriteria classCode=\"OBS\" moodCode=\"DEF\" xmlns:v3=\"urn:hl7-org:v3\"><v3:code code=\"KSUBJ\" codeSystem=\"2.16.840.1.113883.5.4\" xmlns:v3=\"urn:hl7-org:v3\"/><v3:value code=\"238.4\" codeSystem=\"2.16.840.1.113883.6.103\" displayName=\"\" xmlns:v3=\"urn:hl7-org:v3\"/></v3:mainSearchCriteria><v3:informationRecipient typeCode=\"IRCP\" xmlns:v3=\"urn:hl7-org:v3\"><v3:patient classCode=\"PAT\" xmlns:v3=\"urn:hl7-org:v3\"/></v3:informationRecipient></category><id></id><entry><title>Bone Marrow Diseases</title><link href=\"http://www.nlm.nih.gov/medlineplus/bonemarrowdiseases.html\" rel=\"alternate\"/><id>tag: nlm.nih.gov, 2013-13-09:/medlineplus/bonemarrowdiseases.html</id><updated>2013-09-13T12:09:48Z</updated><summary type=\"html\"><p>Bone marrow is the spongy tissue inside some of your bones, such as your hip and thigh bones. It contains immature cells, called stem cells. The stem cells can develop into the red blood cells that carry oxygen through your body, the white blood cells that fight infections, and the platelets that help with blood clotting. </p>

<p>If you have a bone marrow disease, there are problems with the stem cells or how they develop. <a href=\"http://www.nlm.nih.gov/medlineplus/leukemia.html\">Leukemia</a> is a cancer in which the bone marrow produces abnormal white blood cells. With <a href=\"http://www.nlm.nih.gov/medlineplus/aplasticanemia.html\">aplastic anemia</a>, the bone marrow doesn't make red blood cells. Other diseases, such as <a href=\"http://www.nlm.nih.gov/medlineplus/lymphoma.html\">lymphoma</a>, can spread into the bone marrow and affect the production of blood cells. Other causes of bone marrow disorders include your genetic makeup and environmental factors.</p> 

<p>Symptoms of bone marrow diseases vary. Treatments depend on the disorder and how severe it is. They might involve medicines, blood transfusions or a <a href=\"http://www.nlm.nih.gov/medlineplus/bonemarrowtransplantation.html\">bone marrow transplant</a>. </p>
 <p class=\"NLMrelatedLinks\"><ul><li><a href=\"http://www.nlm.nih.gov/medlineplus/ency/article/003658.htm\">Bone marrow aspiration</a></li><li><a href=\"http://www.nlm.nih.gov/medlineplus/ency/article/003934.htm\">Bone marrow biopsy</a></li><li><a href=\"http://www.nlm.nih.gov/medlineplus/ency/article/003682.htm\">Bone marrow culture</a></li><li><a href=\"http://www.nlm.nih.gov/medlineplus/ency/article/003009.htm\">Bone marrow transplant</a></li><li><a href=\"http://www.nlm.nih.gov/medlineplus/ency/patientinstructions/000010.htm\">Bone marrow transplant - discharge</a></li><li><a href=\"http://www.nlm.nih.gov/medlineplus/ency/article/000589.htm\">Polycythemia vera</a></li><li><a href=\"http://www.nlm.nih.gov/medlineplus/ency/article/000531.htm\">Primary myelofibrosis</a></li></ul></p></summary></entry></feed> \n\n"
也就是说,它以字符串形式返回 HTML
,正如您所期望的那样。
最佳答案
看来您需要更新的 ruby,请参阅 ruby bug report
您可以“强制”open-uri 使用 ip 例如:
require 'open-uri'
require 'socket'
url = "google.com"
ip = IPSocket::getaddress(url)
open("http://#{url}") do |f|
puts "i'm using url #{url} #{f.base_uri}"
end
open("http://#{ip}") do |f|
puts "i'm using ip #{ip} #{f.base_uri}"
end
关于ruby-on-rails - Ruby:强制 open-uri 返回 IPv4 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18793868/
使用 ruby 1.9.2-p290。我在尝试解析如下 URI 时遇到问题: require 'uri' my_uri = "http://www.anyserver.com/getdata?anyp
根据 http://tools.ietf.org/html/rfc3986和 http://en.wikipedia.org/wiki/Uniform_resource_identifier , UR
如何在文本 block 中发现 URI? 这个想法是将这样的文本运行变成链接。如果只考虑 http(s) 和 ftp(s) 方案,这很容易做到;但是,我猜测一般问题(考虑 tel、mailto 和其他
我的一些网址上有一些特殊字符。例如: http://blabla.com/title/?t=burası 当我从其他页面提供指向该页面的链接时,我使用: URI.encode(s) 产生这个链接: /
我在 Windows Mobile 上使用紧凑型框架/C#。 在我的应用程序中,我通过序列化对象并使用 HttpWebRequest/POST 请求向上发送信息来将数据上传到服务器。在服务器上,发布数
我正在做一个实验,我发现将 Canvas 转换为 blob,然后转换为数据 URI 会导致与直接从 Canvas 获取数据 URI 不同的 URI。打开时的内容在两个 URI 上几乎相同。 使用 bl
我正在尝试在 Rails 3 中实现 OAuth 提供程序。当我尝试授权客户端应用程序时,出现此错误。我正在使用 RESTful auth 插件和 pelles OAuth 插件。当我通过 Rails
我有一个编码的 UI 测试方法: public void MyTestMethod() { string baseUrl = "www.google.com"; GlobalVaria
我知道这是一个常见的错误,我正在使用一个已知的解决方案,但它仍然给我同样的错误: require 'open-uri' url = "http://website.com/dirs/filex[a]"
我正在尝试使用 .NET 中的 HttpClient 来使用 Web 服务,并且在我完成了 msdn 中提到的所有步骤之后 o 出现以下异常:提供了无效的请求 URI。请求 URI 必须是绝对 URI
我正在尝试检索文件的 URI。该文件存储在: /storage/emulated/0/AppName/FileName.png 如果我使用 Uri.fromFile(file),我得到的是 file:
我想知道 (SIP) URI 中的不同参数分隔符表示什么? 部分以;分隔,例如: . 其他用?隔开和 & ,例如: 最佳答案 SIP 分隔符规则来自RFC 2396 RFC 3986 已弃用.但是在
我想调用decodeUrl(...),我这样做是: import "dart:uri"; main() { decodeUrl("str"); } 但是现在有了最新的Dart-SDK,它会报告
在 URI 中,空格可以编码为 + .既然如此,那么在创建具有国际前缀的 tel URI 时是否应该对前导加号进行编码? 哪个更好?两者在实践中都有效吗? Call me Call me 最佳答案 不
我试图弄清楚电子邮件地址的格式是否可以说符合 URI 的定义,但到目前为止我还没有找到明确的确认。我希望有人可以在这里为我提供一些见解。预先感谢:) 最佳答案 是的,但带有“mailto:”前缀。 U
因此,我尝试将 ID 参数附加到 URI 的末尾,当用户单击我的列表中的项目时,用户将被发送到该 URI。我的代码如下: public void onItemClick(AdapterView par
这是 Converting file path to URI 的后续问题. 考虑: require 'uri' uri = URI.join('file:///', '/home/user/dir1/
我在 pl/sql 中创建了一个名为 tester 的包。但我收到以下消息。 绝对URI中的相对路径:java.net.URI.checkPath(URI.java:1823) --Package D
我在 gitlab 上有一个 git repo,使用私有(private) pod 和其他公共(public) pod,下面是我的 Podfile source 'git@gitlab.mycompa
我正在尝试将我的 Rails 应用程序推送到 heroku 上,我正在使用 heroku RedisToGo 附加组件我经历过这个tutorial并完成了那里提到的所有步骤。 但是在推送 heroku
我是一名优秀的程序员,十分优秀!