我正在使用 Delphi XE2 编写我的第一个 Unicode 应用程序,我偶然发现了对GET
Unicode URL 的请求的问题。
简而言之,这是 MP3 标记应用程序中的一个例程,它获取曲目标题和艺术家,并在 Last.FM 中查询相应的专辑、曲目编号和流派。
我有以下代码:
function GetMP3Info(artist, track: string) : TMP3Data //<---(This is a record)
var
TrackTitle,
ArtistTitle : WideString;
webquery : WideString;
[....]
WebQuery := UTF8Encode('http://ws.audioscrobbler.com/2.0/?method=track.getcorrection&api_key=' + apikey + '&artist=' + artist + '&track=' + track);
//[processing the result in the web query, getting the correction for the artist and title]
// eg: for artist := Bucovina and track := Mestecanis, the corrected values are
//ArtistTitle := Bucovina;
// TrackTitle := Mestecăniș;
//Now here is the tricky part:
webquery := UTF8Encode('http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=' + apikey + '&artist=' + unescape(ArtistTitle) + '&track=' + unescape(TrackTitle));
//the unescape function replaces spaces (' ') with '+' to comply with the last.fm requests
[some more processing]
end;
a 中的 webqueryTMemo
看起来恰到好处:
然而,当我尝试使用(属性设置为)GET
向 webquery 发送请求时,我在 Wireshark 中看到正在使用 ANSI 请求 URL 发送数据:TIdHTTP
ContentEncoding
'UTF-8'
TIdHTTP
GET
/2.0/?method=track.getInfo&api_key=e5565002840xxxxxxxxxxxxxx23b98ad&artist=Bucovina&track=Mestec?ni?
以下是GET
请求和响应的完整标头:
GET /2.0/?method=track.getInfo&api_key=e5565002840xxxxxxxxxxxxxx23b98ad&artist=Bucovina&track=Mestec?ni? HTTP/1.1
Content-Encoding: UTF-8
Host: ws.audioscrobbler.com
Accept: text/html, */*
Accept-Encoding: identity
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.23) Gecko/20110920 Firefox/3.6.23 SearchToolbar/1.22011-10-16 20:20:07
HTTP/1.0 400 Bad Request
Date: Tue, 09 Oct 2012 20:46:31 GMT
Server: Apache/2.2.22 (Unix)
X-Web-Node: www204
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Max-Age: 86400
Cache-Control: max-age=10
Expires: Tue, 09 Oct 2012 20:46:42 GMT
Content-Length: 114
Connection: close
Content-Type: text/xml; charset=utf-8;
<?xml version="1.0" encoding="utf-8"?>
<lfm status="failed">
<error code="6">
Track not found
</error>
</lfm>
令我困惑的问题是,我是否在监督与设置TIdHTTP
组件属性相关的任何事情?如何阻止我在应用程序中编写的格式正确的 URL 以错误的格式发送到服务器?