2

I'm having difficulty in Matlab connecting to a local webserver and sending POST data to and from a simple script. (I'm new to urlread/write and webread/write and very new to PHP).

My Matlab script:

myURL = 'http://localhost:8000/webhook/matlabTest.php';
[s status] = urlread(myURL,'post',{'test','data'});
disp(status);

My PHP script:

<?php
$raw_text = json_encode($_POST);
echo "triggered " . $raw_text;

I've also tried in Matlab:

options = weboptions('RequestMethod','post');
[s status] = webread(myURL,'test','data',options);
disp(status);

I keep getting the Matlab error :

The server returned the message: "Connection refused" for URL, 'http://localhost:8000/webhook/matlabTest.php' (with HTTP response code 400)

but if I put http://localhost:8000/webhook/matlabTest.php in my browser it works fine.

Any help would be appreciated!

3
  • 1
    400 is "bad request". something about what matlab is sending is not liked by the server.
    – Marc B
    Commented Aug 25, 2016 at 14:37
  • I changed the matlab to use GET and it is sending 'localhost:8000/webhook/matlabTest.php?test=data'. And then modified the PHP script to $raw_text = json_encode($_GET);
    – jo phul
    Commented Aug 25, 2016 at 14:39
  • is there still a question?
    – Finn
    Commented Aug 25, 2016 at 14:50

1 Answer 1

0

Figured it out. Silly really. Port 8000 is for the netbeans internal server used for development only. I moved the file to my Apache server on port 8080 and all works as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.