web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Business Central forum

Send response to Web Service

(0) ShareShare
ReportReport
Posted on by 425

Hello Everyone,

I am trying to access web service. In one of the web service, where i need to get response from it. I was able to do that.

(Refered : https://www.youtube.com/watch?v=hNuC8V9T1tU)

But in another web service, where i need to pass a parameter. I am unable to achieve it. 

Please suggest.

Thanks!!!

Categories:
I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Can we see a piece of code? How you pass this parameter?

  • Manish Ratan Profile Picture
    425 on at

    procedure GetWeb();

       var

           HttpClient: HttpClient;

           HttpResponse: HttpResponseMessage;

           ResponseText: Text;

           URL: Text;

           SubFolder: Text[100];

           OrderNo: Code[20];

           HttpRequest: HttpRequestMessage;

           HttpsContent: HttpContent;

       begin

           SubFolder := 'ArtWork';  //Currenly passing hardcode value

           OrderNo := 'SO12345';  //Currenly passing hardcode value

           URL := StrSubstNo('xyz.com/create/' + OrderNo + '/' + SubFolder);

           //HttpRequest.SetRequestUri(URL);

           IF HttpClient.Post(URL, HttpsContent, HttpResponse) THEN BEGIN

               HttpResponse.Content.ReadAs(ResponseText);

               Message(ResponseText);        

           END;

       end;

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Is the url correct? Are you sure that the WS want parameters passed in this way?

    What error do you have?

  • Manish Ratan Profile Picture
    425 on at

    Yes, URL is correct. And  WS is requesting parameter in this way.

    http://xyz.com/create/{Parameter1}/{Parameter2}

  • Manish Ratan Profile Picture
    425 on at

    Request to Please suggest a way to pass parameter in Web Service.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    It depends on the called WS. If this is a GET, your code is good I think. But if you need to perform a POST, normally you've to pass the request body.

  • Manish Ratan Profile Picture
    425 on at

    Thanks!!!

    Can you please suggest sample code to pass the request body.

  • jdecottignies Profile Picture
    217 on at

    I think you could to that with JsonObject if I understood correctly)

    procedure YourProcedure()

    var

           Client: HttpClient;

           Content: HttpContent;

           Response: HttpResponseMessage;

           jObj: JsonObject;

           OrderNo: Code[20];

           SubFolder: Text;

    begin

          SubFolder := 'ArtWork';  //Currenly passing hardcode value

          OrderNo := 'SO12345';  //Currenly passing hardcode value

           JobJ.Add('Parameter1', OrderNo);

           jObj.Add('parameter2', SubFolder);

           Content.WriteFrom(Format(jObj));

          Client.Post('http://xyz.com/create/', Content, Response);

    end;

    Is it what you want to do ?

  • jdecottignies Profile Picture
    217 on at

    (The URL I passed in the first parameter of client.post has to end at create, sorry for the characters "&# 39" after)

  • Manish Ratan Profile Picture
    425 on at

    Thanks jdecottignies for your reply.

    I tried the above code, but no luck.

    :(

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans