0

I am struggling to convert this VB.NET code to PHP as It is from an API, and they have no php code examples for me to check my code, or any before or after if there is an issue, So I cannot tell if it is this function which is not working or there is an issue with the API

Const PSK As String = "YOUR_PSK_GOES_HERE"

Function Request(url As String, json As String) As String
    Dim client = New WebClient()
    client.Headers(HttpRequestHeader.ContentType) = "application/json"
    Dim sig = Sign(json + PSK)
    Return client.UploadString(url + "?Format=JSON&Signature=" + sig, json)
End Function

This is my solution

function request($url, $json) {
    $psk = "--------";
    $sig = sign($json . $psk);
    $url = $url . "?Format=JSON&Signature=" . $sig . $json;
    $result = file_get_contents($url);
    return $result;
 }

I am unsure how to attach the , json, inside the UploadString

Am I making a mistake?

  • 1
    `UploadString(Uri, String)` performs a POST request, sending `String` as the data. How to make a POST request using `file_get_contents` – easy enough to research, https://stackoverflow.com/q/2445276/1427878 – CBroe Mar 30 '21 at 11:11
  • `sign` is not a native PHP function though, so where is that coming from in your attempt? Did you code anything to try and calculate the required signature? – CBroe Mar 30 '21 at 11:12
  • Yes that is a function I have created beforehand and know is working, Ah yes I will look at that url and try the 1st answer, I think it is what I am looking for – jacob iluet Mar 30 '21 at 11:26

0 Answers0