Sending Encryption Report To The Server
4.1 Preparing the HTTP Request
1. **Endpoint URL**:
Obtain the specific URL of the server endpoint designed to receive the encrypted data. This URL will be provided as part of your API documentation or directly within your account on app.offerghosting.com.
2. **Headers**:
– `Content-Type`: Set this header to `application/json` to indicate the nature of the data being sent.
– `Authorization`: Use this header to pass your `subscriptionKey`. The exact format may vary based on the server’s requirements, but it typically follows a standard such as `Bearer <your_subscriptionKey>`.
3. **Request Body**:
Include the encrypted ‘Report Ghosting’ data as part of the request body. Depending on the API’s design, this may involve embedding the encrypted data within a larger JSON structure or sending it directly as the body’s content.
4.2 Example HTTP POST Request in Various Languages
**JavaScript (using Fetch API):**
async function sendEncryptedData(encryptedData) {
const subscriptionKey = ‘your_subscriptionKey_here’; // Replace with your actual subscriptionKey
const url = ‘https://ogp.offerghosting.com//call-candidate-score’;
// Replace with the actual endpoint URL
try {
const response = await fetch(url, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({ subscriptionKey: subscriptionKey, queryData: queryData })
})
});
if (response.ok) {
const jsonResponse = await response.json();
console.log(‘Success:’, jsonResponse);
} else {
console.error(‘Server responded with a status:’, response.status);
}
} catch (error) {
console.error(‘Failed to send encrypted data:’, error);
}
}
**Python (using Requests library):**
import requests
def send_encrypted_data(encrypted_data):
subscription_key = ‘your_subscriptionKey_here’ # Replace with your actual subscriptionKey
url = ‘https://ogp.offerghosting.com/call-candidate-score’
# Replace with the actual endpoint URL
headers = {
‘Content-Type’: ‘application/json’,
}
data = { ‘subscriptionKey’: subscription_key, ‘encryptedData’: encrypted_data }
response = requests.post(url, headers=headers, json=data)
if response.ok:
print(‘Success:’, response.json())
else:
print(‘Server responded with a status:’, response.status_code)
send_encrypted_data(encrypted_data)
**C# (.NET using HttpClient):**
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class ReportSender
{
public static async Task SendEncryptedDataAsync(string encryptedData)
{
var subscriptionKey = “your_subscriptionKey_here”; // Replace with your actual subscriptionKey
var url = “https://ogp.offerghosting.com//call-candidate-score”; // Replace with the actual endpoint URL
var client = new HttpClient();
var data = JsonConvert.SerializeObject(new { subscriptionKey = subscriptionKey, encryptedData = encryptedData });
var content = new StringContent(data, Encoding.UTF8, “application/json”);
var response = await client.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
var jsonResponse = await response.Content.ReadAsStringAsync();
Console.WriteLine(“Success:”, jsonResponse);
}
else
{
Console.WriteLine($”Server responded with a status: {response.StatusCode}”);
}
}
}
These examples demonstrate how to send the encrypted ‘Report Ghosting’ data to the server using the subscription key for authentication. The key aspects are constructing the correct HTTP headers, formatting the request body appropriately, and handling the server’s response to ensure the data has been transmitted successfully.