0

I want to do some m2m-communication, where my server is to emulate a human operating a webpage.

So I'm trying to SEND an XMLHttpRequest from php TO another server.

Whatever I've searched for gives how for php to ACCEPT a XMLHttpRequest

I have debugged the browser, and Chrome webdeveloper tools have given me a cURL cmd which works.

The curl cmd ends in

 --data-binary '[{"productNumber":"12345678","quantity":1}]' 

I'm using snoopy to send the requests, and have emulated every cookie and header, but the server still responds with 400 Invalid Request.

I think the problem lies in that snoopy usually is used like this:

$submit_vars['email'] = "johndoe@example.com";
$submit_vars['password'] = 'secret';
$snoopy->submit($submit_url, $submit_vars);

i.e. Snoopy expects an array of form variables, not a string.

Is there a way to make snoopy send the equivalent of curl --data-binary ?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Leif Neland
  • 1,416
  • 1
  • 17
  • 40
  • 1
    Use the `curl` functions to send requests from PHP. – Barmar Mar 01 '18 at 01:03
  • Snoopy emulates ordinary web forms. The API you want to call expects the data in JSON format, which is not how web forms work. You'll need to do it with curl, not snoopy. – Barmar Mar 01 '18 at 01:06
  • Yeah.I got it working with curl. As I already knew the format of the curl-cmd I found it easyest (?) to just generate a string and exec it. As curl is only being fed auto-generated json from safe database values, I see no risk, and the performance difference is negiable. – Leif Neland Mar 01 '18 at 01:28

0 Answers0