2023-04-05 09:34 AM - edited 2023-04-05 11:39 AM
I want to send a .xlsx file to the server using Restful POST request in a multipart-form data. I am able to send normal text in POST body, but how do i send a file. I am using Communication::Client::Http::HttpClientRequest as shown in CommunicationClient_test example in SDK.
2023-10-17 06:18 AM - edited 2023-10-17 08:31 AM
Hi Ankur,
I was able to get response from the call with status 200, but not able to parse the response using the code below
using namespace HTTP::Client;
using namespace HTTP::MessageHeader;
using namespace GS::IBinaryChannelUtilities;
IO::URI::URI connectionUrl ("https://identity.thenbs.com/");
ClientConnection clientConnection (connectionUrl);
clientConnection.Connect ();
Request postRequest (Method::Post, "/core/connect/token");
GS::UniString clientID = "user";
GS::UniString clientSecret = "pass";
// More information on the API, and on getting an API key:
// https://toolkit.thenbs.com/articles/for-software-developers/#bimToolkitAPI
RequestHeaderFieldCollection& headers = postRequest.GetRequestHeaderFieldCollection ();
Authentication::BasicAuthentication auth (clientID, clientSecret);
auth.HandleRequestHeaderFieldCollection (headers);
headers.Add (HeaderFieldName::ContentType, "application/x-www-form-urlencoded");
GS::UniString postBody = "scope=bimtoolkitapi&grant_type=client_credentials";
clientConnection.Send (postRequest, postBody.ToCStr (), postBody.GetLength ());
Response response;
JSON::JDOMParser parser;
JSON::ValueRef parsed = parser.Parse (clientConnection.BeginReceive (response));
DBPrintf ("HTTP %u\n", response.GetStatusCode ());
if (response.GetStatusCode () == StatusCode::OK) {
JSON::ObjectValueRef object = GS::DynamicCast<JSON::ObjectValue> (parsed);
JSON::StringValueRef tokenValue = GS::DynamicCast<JSON::StringValue> (object->Get ("access_token"));
if (tokenValue != nullptr) {
GS::UniString token = tokenValue->Get ();
DBPrintf ("NBS Token: %s\n", token.ToCStr ().Get ());
}
}
clientConnection.FinishReceive ();
clientConnection.Close (false);
Could you help on this?