Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Problem ServerRequest
Wed, Sep 30 2015 6:41 AMPermanent Link

Pasquale

Web Pos srl

I implementation this code for the ServerRequest

StringaValore := '10';
ServerEuronet.URL := 'http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit';
ServerEuronet.Method := rmPost;

ServerEuronet.RequestContent.Clear;
ServerEuronet.RequestContent.Add('<?xml version="1.0" encoding="utf-8"?>');
ServerEuronet.RequestContent.Add('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="'" name="http://www.w3.org/2003/05/soap-envelope">'">http://www.w3.org/2003/05/soap-envelope">');
ServerEuronet.RequestContent.Add('<soap12:Body>');
ServerEuronet.RequestContent.Add('<CelsiusToFahrenheit xmlns="'" name="http://www.w3schools.com/webservices/">'">http://www.w3schools.com/webservices/">');
ServerEuronet.RequestContent.Add('<Celsius>' + StringaValore + '</Celsius');
ServerEuronet.RequestContent.Add('</CelsiusToFahrenheit>');
ServerEuronet.RequestContent.Add('</soap12:Body>');
ServerEuronet.RequestContent.Add('</soap12:Envelope>');

ServerEuronet.RequestHeaders.Clear;
ServerEuronet.RequestHeaders.Add('POST /webservices/tempconvert.asmx HTTP/1.1');
ServerEuronet.RequestHeaders.Add('Host: www.w3schools.com');
ServerEuronet.RequestHeaders.Add('Content-Type: application/soap+xml; charset=utf-8');
ServerEuronet.RequestHeaders.Add('Content-Length: '+ IntToStr(Length(ServerEuronet.RequestContent.Text)));

ServerEuronet.OnComplete := ServerEuronetComplete;   
ServerEuronet.Execute;


procedure TFormRicaricheP.ServerEuronetComplete(Request: TServerRequest);
begin
if (Request.StatusCode=HTTP_OK) then
Begin
  ShowMessage('Risultato Request : '+Request.ResponseContent.Text);
End
else
raise Exception.Create('Errore Server Euronet : '+Request.StatusText);
end;


the services html page is : http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit

but i result only ERROR why ?
Wed, Sep 30 2015 7:39 AMPermanent Link

Walter Matte

Tactical Business Corporation

Wed, Sep 30 2015 8:17 AMPermanent Link

Matthew Jones

Pasquale wrote:

> ServerEuronet.RequestHeaders.Clear;
> ServerEuronet.RequestHeaders.Add('POST /webservices/tempconvert.asmx
> HTTP/1.1'); ServerEuronet.RequestHeaders.Add('Host:
> www.w3schools.com'); ServerEuronet.RequestHeaders.Add('Content-Type:
> application/soap+xml; charset=utf-8');
> ServerEuronet.RequestHeaders.Add('Content-Length: '+
> IntToStr(Length(ServerEuronet.RequestContent.Text)));

I'd be suspicious of doing the header things yourself. I'd expect only
authentication things would be needed. The host is part of the request
itself I think? And the content type is set with a property.

--

Matthew Jones
Wed, Sep 30 2015 8:18 AMPermanent Link

Matthew Jones

Also, try things out with PostMan (a Chrome application) and see how
that does it. Using a REST tool to pre-flight my calls and replicate
them has been quite handy for me.

--

Matthew Jones
Wed, Sep 30 2015 9:14 AMPermanent Link

Raul

Team Elevate Team Elevate

On 9/30/2015 6:41 AM, Pasquale wrote:
> I implementation this code for the ServerRequest
> the services html page is : http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit
> but i result only ERROR why ?


Using the Test section and examining the response header there is no
"Access-Control-Allow-Origin" - therefore this will never work with any
external query as they do not allow it. I assume this is just a sample
page and they want you to host it on YOUR web server.

Otherwise the basic query would be like this - i'm using HTTP POST
version as it's way easier to use than SOAP ones:

ServerRequest1.URL :=
'http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit';
ServerRequest1.Method := rmPost;
ServerRequest1.RequestHeaders.Clear;
ServerRequest1.RequestHeaders.Add('Content-Type:
application/x-www-form-urlencoded');
ServerRequest1.RequestContent.text := 'Celsius=12';
ServerRequest1.Execute;



Raul
Image