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

1
  • 1
    cURL ? Commented Apr 10, 2012 at 13:58

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

0

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.