警告:fopen无法打开流:HTTP请求失败! HTTP / 1.1 406在/XAMPP/xamppfiles/htdocs/search.php中不可接受 [英] Warning: fopen failed to open stream: HTTP request failed! HTTP/1.1 406 Not Acceptable in /XAMPP/xamppfiles/htdocs/search.php

查看:253
本文介绍了警告:fopen无法打开流:HTTP请求失败! HTTP / 1.1 406在/XAMPP/xamppfiles/htdocs/search.php中不可接受的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从pubmed获取搜索结果。

I am trying to fetch search results from pubmed.

$query=(BRCA1[tiab]) OR (Breast cancer 1 gene[tiab])AND (Cancer[tiab])
$esearch = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=$query&retmax=10&usehistory=y';
$handle = fopen($esearch, "r");
$rettype = "abstract"; //retreives abstract of the record, rather than full record
$retmode = "xml";

我收到此HTTP访问失败错误。

I get this HTTP Access Failure error.

错误:


警告:fopen( http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=(BRCA1 [tiab])或(乳腺癌1基因[tiab])AND (Cancer [tiab])& retmax = 10& usehistory = y):无法打开流:HTTP请求失败!第60行/Applications/XAMPP/xamppfiles/htdocs/search.php中不能接受HTTP / 1.1 406

Warning: fopen(http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=(BRCA1[tiab]) OR (Breast cancer 1 gene[tiab]) AND (Cancer[tiab])&retmax=10&usehistory=y): failed to open stream: HTTP request failed! HTTP/1.1 406 Not Acceptable in /Applications/XAMPP/xamppfiles/htdocs/search.php on line 60

当我直接粘贴url, http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=(BRCA1[tiab])或(乳腺癌1基因[tiab])AND(癌症[tiab])& retmax = 10& usehistory = y我在页面中获得搜索结果,但在通过php脚本访问时没有。

When I directly paste the url, http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=(BRCA1[tiab]) OR (Breast cancer 1 gene[tiab]) AND (Cancer[tiab])&retmax=10&usehistory=y I get search results in the page but not when accessing through the php script.

推荐答案

这里有一些问题。首先,您在第一行有一个语法错误,其中您有没有引号的纯文本。我们可以通过替换这一行来解决这个问题:

There are a few issues here. First, you have a syntax error on the first line, where you have plain text without quotes. We can fix that by replacing this line:

$query=(BRCA1[tiab]) OR (Breast cancer 1 gene[tiab])AND (Cancer[tiab]) 

这一行:

$query = "(BRCA1[tiab]) OR (Breast cancer 1 gene[tiab])AND (Cancer[tiab])";

现在修复了语法错误。

This now fixes that syntax error.

其次,你的第二行有一个无声字符串连接错误。如果要内联连接变量(不使用运算符),则必须使用双引号,而不是单引号。让我们通过替换这一行来解决这个问题:

Secondly, you have a silent string concat error in your second line. If you want to concatenate variables inline (without using the . operator) you have to use double quotes, not single quotes. Let's fix that by replacing this line:

$esearch = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=$query&retmax=10&usehistory=y'; 

此行:

$esearch = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=$query&retmax=10&usehistory=y"; 

最后,你没有对查询进行urlencoding,因此你的URL中有空格没有编码,并搞乱了fopen的URL。让我们将查询字符串包装在 urlencode()中:

Lastly, you're not urlencoding the query, thus you're getting spaces in your URL that are not encoded and are messing up the URL for fopen. Let's wrap the query string in urlencode():

$query = urlencode("(BRCA1[tiab]) OR (Breast cancer 1 gene[tiab])AND (Cancer[tiab])");
$esearch = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=$query&retmax=10&usehistory=y"; 
$handle = fopen($esearch, "r"); 
$rettype = "abstract"; //retreives abstract of the record, rather than full record 
$retmode = "xml"; 

我在CLI上测试了这段代码,它似乎工作正常。

I tested this code on CLI and it seems to work correctly.

这篇关于警告:fopen无法打开流:HTTP请求失败! HTTP / 1.1 406在/XAMPP/xamppfiles/htdocs/search.php中不可接受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆