Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP Request

dushyant
Booster

Hi

I need to make a HTTP request with the GET method, in this form:

https://someurl.com/api/somecode?param1=val1&param2=val2

Request prepared as:

request = GS::StaticCast<Communication::Client::Http::HttpClientRequest> (clientConnection->CreateRequest ());

There was some example which takes the requestMethod (not 'GET' or 'POST' but some path like "/api/ip") and a requestMethodId in the form of "some-text-with-hyphens"

request->SetRequestLine (Communication::Http::RequestLine (request->GetRequestLine ().GetProtocolVersion (), "GET", request->GetRequestLine ().GetUri () + requestMethod));
request->SetId (requestMethodId);

 

Is this example made just for accessing a specific API? I could not figure out what that requestMethodId would be in generic cases.

Can someone please tell how to make a generic HTTP request using class COMMUNICATIONCLIENT_API ClientRequest ?

Thanks!

2 REPLIES 2

Tibor Lorantfy
Graphisoft
Graphisoft

Hi,

 

The CommunicationClient_Test Exmple Add-On shows a simple example for using REST API, but the example can work for any other REST APIs with minimal modifications.

It's not required to use the SetId function. That depends on the server side implementation. That could be for example a session identifier or an identifier of various REST API methods. So if the used service does not require any id, then simply don't care about requestMethodId 😉

 

I see that you will have to pass parameters also. Use the AddParameter function of the request to define the parameters.

Hi Tibor,

I removed the SetId() function and passed the requestMethod as the part-URL (removing the base URL), and also passed the parameters of type Communication::Parameter.

The try-catch is returning an ExceptionError ('The server failed to fulfil the request').

I added the parameters as:

request->AddParameter(param)

and also tried:

request->SetParameter(param)

both before and after request->SetRequestLine(). I'm getting the same exception-error.

After adding the parameters to 'request', I checked the parameter count:

request->GetParameterCount(), it returns the correct number of parameters added.

 

What could be going wrong? Is there a way to get the exact error-message received in the response?

 

Thanks.

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!