Rest api instead of php curl

Rest api instead of php curl

  
Hi Guys,

We want to send information from the OS platform to a client website.
The client provides us of a php file that we can use to send information to there server.
Only we want to send it from OS so where trying to find a whay of doing this.
The code that there providing us:

$ch = curl_init();
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_VERBOSE, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_USERPWD, "{$this->username}:{$this->password}");
            curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
            curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
            curl_setopt($ch, CURLOPT_POST, true);
            
            $file = new CurlFile($this->pdffile);
            
            $post_array = array(
                "my_file"=> $file,
                "upload"=>"Upload", 
                "send"=>True
            );
            curl_setopt($ch, CURLOPT_URL,  $this->url);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
            $response = curl_exec($ch);

I was trying to use the REST API from OS adding the input parameter upload is not a problem only how to add the file?
Hi,

Why use rest api at all?
Why not simply use the PostRequest_* actions from httprequesthandler extension?


The url of the customer is a https url with authentication. I also could not get the PostRequest working. It returns the error 401. Already tried to add a header authentication with value= binarytobase64(stringtobinary((user:pass)) but that also not works.

Also I tried to add the user and pass in the url of the PostRequest:
Url: https://user:pass@url.com
value should be "Basic " + binarytobase64(texttobinary(user+":"+password, "utf-8"))
See my flow, with the add header I do:

name:
"Authorization"
value:
"Basic " + BinaryToBase64(TextToBinaryData("user:pass", "utf-8"))

Only still getting the 401 error.


assuming user:pass is the actual user and password which are not revealed now :)

perhaps it's something else, but could you paste the encoded authorisation in php and test if it works there?
or soapui or something else.. so you know it's not the encoding that is incorrect?
I already test the php api that they gave me and that one is working, so with curl its working.

I would belive that the Add Header will not have inpact on the submit, because the header is not connected to the submit. So I think this will not be possible. I already tried it with the resp api from OS and that is working only I then cannot add the binary file to it. Im stuck here :(
i meant the encoded authorisation...

if you can provide me with a demo username + password and url and i check it for myself.