xdmp:http-get($url,
<options xmlns="xdmp:document-get">
<format>binary</format>
</options>)[2]
上面的查詢不返回從代理服務器的響應。我知道IP地址和端口號以獲得代理服務器中的響應。有誰知道在哪裏添加IP和端口號?
MarkLogic版本:7.x的
最近,我試圖在http://markmail.org/message/sbfj44jtmpsyopyh與下面的代碼討論配置代理。
let $proxy := "http://171.21.15.60:3128"
let $uri := "http://www.austlii.edu.au/cgi-bin/sinosrch.cgi?results=200;query=damage"
let $host := tokenize($uri,'/')[3]
let $proxyuri := concat($proxy, '/', tokenize($uri, '/')[last()])
return xdmp:http-post(
$proxyuri,
<options xmlns="xdmp:http">
<headers>
<Host>{$host}</Host>
</headers>
</options>
)
但是我收到了一個錯誤的請求作爲迴應。
<response xmlns="xdmp:http">
<code>400</code>
<message>Bad Request</message>
<headers>
<server>squid/3.1.4</server>
<mime-version>1.0</mime-version>
<date>Thu, 20 Nov 2014 04:09:50 GMT</date>
<content-type>text/html</content-type>
<content-length>3071</content-length>
<x-squid-error>ERR_INVALID_URL 0</x-squid-error>
<vary>Accept-Language</vary>
<content-language>en</content-language>
<x-cache>MISS from l076ddms1</x-cache>
<x-cache-lookup>NONE from l076ddms1:3128</x-cache-lookup>
<via>1.0 l076ddms1 (squid/3.1.4)</via>
<proxy-connection>close</proxy-connection>
</headers>
</response>
看看下面的錯誤
以下錯誤時遇到試圖檢索網址:/sinosrch.cgi?results=200;query=damage
誰能幫助我解決這個問題?
謝謝。
大家好,
我仍然得到同樣的迴應,我曾試圖通過@mblakele告訴步驟之後。
declare namespace http="xdmp:http";
declare function local:http-options(
$options as element(http:options)?,
$extra as element(http:options)?)
as element()?
{
if (empty($extra)) then $options
else if (empty($options)) then $extra
else element http:options {
(: TODO - needs to handle conflicting options. :)
$options/*,
$extra/* }
};
declare function local:http-get(
$proxy as xs:string,
$uri as xs:string,
$options as element(http:options)?)
as item()+
{
let $uri-toks := tokenize($uri, '/+')
let $uri-host := $uri-toks[2]
let $options := local:http-options(
$options,
element http:options {
element http:headers {
element http:host { $uri-host } } })
(: TODO support TLS proxies using https. :)
let $uri-proxy := concat(
'http://', $proxy,
substring-after($uri, $uri-host))
return xdmp:http-get($uri-proxy, $options)
};
local:http-get(
'171.21.15.60:3128', 'http://www.austlii.edu.au/cgi-bin/sinosrch.cgi?results=200;query=damage',())
上述代碼的$ URI代理的值:
http://171.21.15.60:3128/cgi-bin/sinosrch.cgi?results=200;query=damage
上述代碼的$ URI主機的值是:
www.austlii.edu.au
$的值以上代碼中的選項爲:
<http:options xmlns:http="xdmp:http">
<http:headers>
<http:host>www.austlii.edu.au</http:host>
</http:headers></http:options>
錯誤是
試圖檢索URL時遇到以下錯誤:/cgi-bin/sinosrch.cgi?results=200;query=damage
我檢查了這個[鏈接](http://markmail.org/message/sbfj44jtmpsyopyh),但是我收到了ML數據庫 – Gowtham
中的錯誤請求作爲響應(如發佈的問題)嘗試一些調試。將查詢修改爲'return($ host,$ proxyuri)',你應該看到'tokenize($ uri,'/')[last()]'太粗糙了。它切斷了路徑的'cgi-bin'部分。相反,新的URI應該包含主機之後的所有內容。見上面我的編輯。 – mblakele
我仍然收到一個不好的請求作爲迴應。匹配($ proxy,'^ \ w +(:\ d +)?$')這不會對我有用。因爲localhost在我的情況下是ip,它不會匹配你寫的正則表達式。所以我刪除了那部分並試了一下。我在我的問題中發佈了$ uri-proxy,$ uri-host,$ options的值。幫助我如何解決這個問題 – Gowtham