I'm trying to figure out how to send this kind of data, via PHP, to a RESTful service:
{
"api_version": 1.0,
"project_id" : 123,
"batch_id" : 111,
"accesskey" : "abc123",
"job": {
"file": file,
"word_count": 111,
"title": "FAQ",
"cms_id": "page_123_en_sp",
"url" : "http://original_post_url.com",
"is_update": false,
"translator_id": 123,
"note": "Translate these words",
"source_language": "en",
"target_language": "it"
}
}
First of all, I cannot use curl, as who's going to use this code might not have it installed or might be not allowed to install it.
That's not a 'normal' JSON object. The job->file property is an actual file (not even an url to a file).
That's the actual code I'm using to send all requests and it worked, until I've met this specific case: http://pastebin.com/6pEjhAkg
The 'file' property is created as such:
$file = generate_file( $content );
protected static function generate_file($content) {
$file = fopen('php://temp','r+');
fwrite($file, $content);
rewind($file);
return $file;
}
Now, when sending data, with $params argument properly set on PHP side, the RESTful returns an error about missing 'api_version' and 'project_id', but they are present. I'm pretty sure the problem is that he's not receiving data as JSON, but how can I convert to JSON an object that, in his properties, contains a file pointer resource?
The code that sends data and builds the file has been created by a former developer, and I can't get in touch with him.
I tried to understand what is wrong there and the only thing I managed to fix so far, for another unrelated issue, is to actually send JSON data (when $multipart==false), as you can see in lines 16-19 of the linked code, rather than sending urlencoded data.
Any hint?