I cannot load image from Zend server with following code:
Console.WriteLine(">" + url);
Console.WriteLine(">" + NSUrl.FromString(url));
Console.WriteLine(">" + NSData.FromUrl(NSUrl.FromString(url))); // Null on this line
It appears only when I’m trying to load image from my server, any other source works fine. Here is my Zend controller code:
public function getAction()
{
$file_id = (int)$this->_getParam('id');
$file = $this->fileModel->getById($file_id);
$this->getResponse()
->setHttpResponseCode(200)
->setHeader('Pragma', 'public', true)
->setHeader('Expires', '', true)
->setHeader('Cache-Control', 'public', true)
->setHeader('Cache-Control', 'max-age=3800')
->setHeader('Content-type', $file->CONTENT_TYPE, true)
->setHeader('Content-Length', $file->FILE_SIZE)
->clearBody();
$this->getResponse()->sendHeaders();
echo base64_decode($file->FILEBODY);
exit;
}
Image showed fine in browser. What’s wrong with my code?
PS: my server works throught HTTPS without any signed certificate
NSData.FromUrl(dataWithContentsOfURL:in Objective-C) will returnnullfor any error.From Apple documentation:
So something went wrong…
Doubtful. You likely have a self-signed certificate (or your server should not be happy). Anyway…
If, when trying your URL, Safari (from your iPhone/iPad) warns you about your site then it falls into the something went wrong category and the
nullvalue you get is normal.You might want to try HTTP: to make sure it’s not related to something else (e.g. networking issues).
Now if you *really want to use an untrusted SSL server you can use some .NET API, e.g.
WebClient.That alone will get you an exception (untrusted SSL server) but IMO that’s already better than simply a
null.Next you’ll need to vouch for the untrusted certificate. There’s a few different ways to do it (some much better than others). I fairly complete list of them (with source) code can be found in this article.