Hi all…
i’m new to Xojo and play around with it for a while and we think to use it in one of our projects here.
We do a lot of Azure stuff and managed API’s in Azure. Now i want to test this with XOJO.
I want to call one of our API’s. I have an example in C# an PHP… Can please someone help me or convert this Code to XOJO so that we can test if it works with our Azure API ?
C# CODE EXAMPLE ------------------------------------------------------------------
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
namespace CSHttpClientSample
{
static class Program
{
static void Main()
{
MakeRequest();
Console.WriteLine(“Hit ENTER to exit…”);
Console.ReadLine();
}
static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add(“SenderTID”, “”);
client.DefaultRequestHeaders.Add(“UserEmail”, “”);
client.DefaultRequestHeaders.Add(“Sender”, “”);
client.DefaultRequestHeaders.Add(“System”, “”);
client.DefaultRequestHeaders.Add(“Ocp-Apim-Subscription-Key”, “{subscription key}”);
var uri = “https://pl.azure-api.net/customer/v1/{sourcesystem}/insert?" + queryString;
HttpResponseMessage response;
// Request body
byte[] byteData = Encoding.UTF8.GetBytes(”{body}");
using (var content = new ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("< your content type, i.e. application/json >");
response = await client.PostAsync(uri, content);
}
}
}
}
PHP CODE EXAMPLE---------------------------------------------------------------------------------------------------------------------
<?php // This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/) require_once 'HTTP/Request2.php'; $request = new Http_Request2('https://pl.azure-api.net/customer/v1/{sourcesystem}/insert'); $url = $request->getUrl(); $headers = array( // Request headers 'SenderTID' => '', 'UserEmail' => '', 'Sender' => '', 'System' => '', 'Content-Type' => 'application/json', 'Ocp-Apim-Subscription-Key' => '{subscription key}', ); $request->setHeader($headers); $parameters = array( // Request parameters ); $url->setQueryVariables($parameters); $request->setMethod(HTTP_Request2::METHOD_POST); // Request body $request->setBody("{body}"); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; } ?>THX for your help !!!
If we are successfull with it then XOJO is my choice for this project…
Greetings
Henning