谁能指出正确的方向?我正在尝试使用新的 Bing API 执行网络搜索,但使用下面的代码,我不断收到“HTTP/1.1 400 Bad Request”。相同的请求在浏览器下运行良好(将用户名留空并在提示框中提供密码下的密钥)。
var
IdHTTP1 : TIdHTTP;
uri : string;
myIOhandler : TIdSSLIOHandlerSocketOpenSSL;
begin
myIOhandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
with myIOhandler do
begin
SSLOptions.Method := sslvTLSv1;
SSLOptions.Mode := sslmUnassigned;
SSLOptions.VerifyMode := [];
SSLOptions.VerifyDepth := 0;
host := '';
end;
IdHTTP1:= TIdHTTP.Create(nil);
IdHTTP1.Request.UserAgent:= 'Mozilla/3.0 (compatible; IndyLibrary)';
IdHTTP1.Request.Accept := 'text/javascript';
IdHTTP1.Request.ContentType := 'application/json';
IdHTTP1.Request.ContentEncoding := 'utf-8';
IdHTTP1.HandleRedirects:= True;
IdHTTP1.ConnectTimeout:= 10000;
IdHTTP1.ReadTimeout:= 10000;
IdHTTP1.Request.CacheControl := 'no-cache';
IdHTTP1.Request.BasicAuthentication:= True;
IdHTTP1.Request.Authentication:= TIdBasicAuthentication.Create;
IdHTTP1.Request.Authentication.Username:= '';
IdHTTP1.Request.Authentication.Password:= APIKey;//Encode64(APIKey);//Encode64(APIKey+':'+APIKey)
IdHTTP1.IOHandler:= myIOHandler;
uri:= 'https://api.datamarket.azure.com/Bing/SearchWeb/Web?'+
'Query=%27'+ query_text +'%27&$format=JSON&$top=50&$skip=0';
s:= IdHTTP1.Get(uri);
MS文档很差。