4

I have data that is contained within a variable (which can be written as a file), but I am looking to send it to a different server using PHP HttpRequest.

I thought of using addRawPostData but I it is deprecated now and I would prefer not to write the file to the client server then try and send it. If anyone has any ideas let me know. I also attempted to submit the raw data from the variable in a field in a normal post but it seems to be corrupted.

The file I am attempting to send is a torrent file, if this makes any difference.

Thanks again

john_science
  • 6,325
  • 6
  • 43
  • 60
vip32
  • 77
  • 1
  • 10

3 Answers3

3

You could use cURL this is a simple example of a HTTP POST :

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.site.com/url");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"key=value&key1=value1");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

// Check response
if ($server_output == "OK") { 

There is an example of POSTing a file string using cURL in this answer

Community
  • 1
  • 1
Manse
  • 37,765
  • 10
  • 83
  • 108
1

To send a file using HttpRequest: http://www.php.net/manual/en/httprequest.addpostfile.php To add raw post data: http://www.php.net/manual/en/httprequest.addrawpostdata.php - HttpRequest::addRawPostData is not deprecated, while HttpRequest::setRawPostData is deprecated.

However, HttpRequest is only a wrapper to cURL and, in some cases, it would be better to use cURL directly.

Timur
  • 6,668
  • 1
  • 28
  • 37
0

use setBody to send rawpost data http://www.php.net/manual/en/httprequest.setbody.php

rijndael
  • 571
  • 5
  • 4