Developer

SAP.Net.Http Workflow

Add SAP.Net.Http to your Windows project.

Context

Obtain the Windows Native Client SDK libraries, which are available as part of the SAP Mobile Platform Client SDK Installer. SAP.Net.Http ships in the form of a NuGet package. The request can handle SAML authentication and an XCSRF token.

To trigger a network request with the HttpClient class of the SAP.Net.Http library, you can use this simple code. In your project, centralize the network handling and separate it from the UI handling.

Procedure

Write code for the GET request and POST request, such as this example shows.
The HttpClient instance is configured to handle XCSRF tokens, BASIC and SAML authentication challenges, and it also sends the connection ID sent by the server after a successful registration in each and every request. If the server sends a BASIC authentication challenge then the username and password values defined in the handler's Credentials property are used. The configured parameters are used on demand (for example the configured SAML parameters are used if and only if the server sends a SAML authentication challenge). If only a simple request is to be sent, the setup of the Credentials property, default headers and SAML parameters can be omitted.
using System.Net.Http;
…
using (var client = new SAP.Net.Http.HttpClient( new System.Net.Http.HttpClientHandler() { Credentials = new NetworkCredential( (string)registrationContext.BackendUserName,
 (string)registrationContext.BackendPassword) }, true ) {

client.DefaultRequestHeaders.TryAddWithoutValidation("X-SMP-APPCID", connectionId);
client.DefaultRequestHeaders.TryAddWithoutValidation("X-SUP-APPCID", connectionId);
client.ShouldHandleXcsrfToken = true;
client.ShouldHandleSamlRequests = true;
client.SamlFinishEndpoint = new UriBuilder("http",registrationContext.ServerHost, registrationContext.ServerPort, "/SAMLAuthLauncher").Uri;
client.SamlFinishEndpointParameter = "finishEndpointParam";

Uri uri = new Uri("http://www.samppleurl.com");
//sending get request
var response = await client.GetAsync(uri);

//sending post request
var response = await client.PostAsync(uri, () => new StringContent("mycontent"));

}