I am trying to upload a file from PHP using cURL to a asp.net mvc 4 controller action.
The file is successfully uploaded on disk after move_uploaded_file is called.
Both .NET MVC and PHP sites are hosted under IIS. I get this HTTP Response:
Bad Request - Invalid Content Length
Has anyone achieved this?
Relevant PHP code:
if(move_uploaded_file($from, $to))
{
$imageFile = '@' . $to . ';type='.$_FILES['file']['type'];
$post_data = http_build_query($_POST);
$post_data["imageFile"] = $imageFile;
$ch = curl_init(self::URL . '/photos/uploadphoto');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($chpg, CURLOPT_POST, count($data));
curl_setopt($chpg, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
}
Relevant .NET C# code:
[HttpPost]
public ActionResult UploadPhoto(HttpPostedFileBase imagefile)
{
// imageFile is null
var file = Request.Files.Count > 0 ? Request.Files[0] : null;
// file is also null
...
}