2013-07-25 4 views
2

나는 http get 요청을 만들기 위해 Delphi 2010을 성공적으로 사용했지만 'xml'이라는 매개 변수를 예상하는 서비스의 경우 'HTTP/1.1 400 Bad Request'오류로 요청이 실패합니다.Tidhttp를 사용하여 xml이라는 매개 변수로 Get 요청을하는 방법은 무엇입니까?

동일한 서비스를 호출하고 'xml'매개 변수를 생략하면 알 수 있습니다. 'xml2'처럼 다른 어떤로 이름이 변경 매개 변수 이름 'XML'와 같은 URL을 호출 ...

HttpGet('http://localhost/Service/Messaging.svc/SendReports/PDF?xml=<?xml version="1.0"?><email><message><to>[email protected]</to><from>[email protected]</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; 

:

는 나는 아무 성공 다음을 시도했다 또는 위와 같은 값을 가진 'name'도 작동합니다. 나는 또한 charset의 여러 조합을 시도했지만 indy 구성 요소가 내부적으로이를 변경한다고 생각합니다.

편집

이 서비스는 기대 :

[WebGet(UriTemplate = "SendReports/{format=pdf}?report={reportFile}&params={jsonParams}&xml={xmlFile}&profile={profile}&id={id}")] 

이 사람이 어떤 경험이 있었나요?

감사

당신은 당신을 위해 URL을 통해 전달할 때, TIdHTTP 인코딩되지 않습니다 URL을 매개 변수 데이터를 인코딩 할 필요가
+0

OT : 문자열을 반환하고'Result'에 직접 할당하는'TIdHTTP.Get' 오버로드를 호출 할 수 있습니다. 그러면 현재 누수되는 스트림 부분을 제거 할 수 있습니다. – TLama

+0

완료. text/xml charset/bad request 문제에 대한 조언이 있으십니까? – reckface

+0

1) 서비스 사양을 보여줍니다. 매개 변수 전달 방법은 무엇입니까? /// 2) WWW 브라우저와 같은 서비스를 성공적으로 호출 할 수있는 참조 데모 프로그램이 있습니까? /// 3) 퍼센트가 아닌 16 진수 인코딩을 사용하여 유효하지 않은 문자를 모두 인코딩하려고 시도하십시오. http://en.wikipedia.org/wiki/Url#List_of_allowed_URL_characters /// 4) 인코딩 된 단어 인 base64 스트림으로 XML을 전달하려고 시도합니다. http://en.wikipedia.org/wiki/MIME#Encoded-Word –

답변

6

, 예를 들면 :

http.Get(TIdURI.URLEncode('http://localhost/Service/Messaging.svc/SendReports/PDF?xml=<?xml version="1.0"?><email><message><to>[email protected]</to><from>[email protected]</from></message></email>&id=42&profile=A1')); 

또는 :

http.Get('http://localhost/Service/Messaging.svc/SendReports/PDF?xml=' + TIdURI.ParamsEncode('<?xml version="1.0"?><email><message><to>[email protected]</to><from>[email protected]</from></message></email>') + '&id=42&profile=A1'); 
+0

고마워요! 그랬어. HTTP 500 오류가 서버에서 온 것으로 나타났습니다. 잠재적으로 위험한 Request.QueryString 값이 클라이언트에서 감지되었습니다. 그에 따라 web.config 파일을 수정했습니다. – reckface

관련 문제