Delphi 2010 を使用して http get リクエストを作成することに成功しましたが、「xml」というパラメータを必要とする 1 つのサービスでは、「HTTP/1.1 400 Bad Request」エラーでリクエストが失敗します。
同じサービスを呼び出して「xml」パラメーターを省略しても機能することに気付きました。
次のことを試しましたが、成功しませんでした:
HttpGet('http://localhost/Service/Messaging.svc/SendReports/PDF?xml=<?xml version="1.0"?><email><message><to>email@internal.com</to><from>from@internal.com</from></message></email>&id=42&profile=A1');
...
function TReportingFrame.HttpGet(const url: string): string;
var
responseStream : TMemoryStream;
html: string;
HTTP: TIdHTTP;
begin
try
try
responseStream := TMemoryStream.Create;
HTTP := TIdHTTP.Create(nil);
HTTP.OnWork:= HttpWork;
HTTP.Request.ContentType := 'text/xml; charset=utf-8';
HTTP.Request.ContentEncoding := 'utf-8';
HTTP.HTTPOptions := [hoForceEncodeParams];
HTTP.Request.CharSet := 'utf-8';
HTTP.Get(url, responseStream);
SetString(html, PAnsiChar(responseStream.Memory), responseStream.Size);
result := html;
except
on E: Exception do
Global.LogError(E, 'ProcessHttpRequest');
end;
finally
try
HTTP.Disconnect;
except
end;
end;
end;
上記と同じ値で「xml2」や「name」のように、パラメーター名「xml」を別の名前に変更して同じ URL を呼び出しても機能します。文字セットの複数の組み合わせも試しましたが、インディコンポーネントが内部で変更していると思います。
編集
サービスは次のことを想定しています。
[WebGet(UriTemplate = "SendReports/{format=pdf}?report={reportFile}¶ms={jsonParams}&xml={xmlFile}&profile={profile}&id={id}")]
誰もこれを経験したことがありますか?
ありがとう