I am creating Shutterstock web application for searching images. take a look on the code
function createImageComponent(image) {
var wrapper = $('<div>');
var thumbWrapper = $('<div>');
var thumbnail = $('<img>');
var description = $('<p>');
$(thumbnail).attr('src', image.assets.preview.url);
$(thumbWrapper)
.addClass('thumbnail-wrapper')
.css('height', image.assets.)
.css('width', image.assets.preview.width)
.append(thumbnail);
$(description)
.text(image.description)
.attr('title', image.description);
$(wrapper)
.addClass('media-wrapper image')
.append(thumbWrapper)
.append(description);
return wrapper;
}
// Create video wrapper component
function createVideoComponent(video) {
var wrapper = $('<div>');
var preview = $('<video>');
var description = $('<p>');
$(preview)
.attr('src', video.assets.thumb_mp4.url)
.attr('controls', true)
.attr('autoplay', true);
$(description)
.text(video.description)
.attr('title', video.description);
$(wrapper)
.addClass('media-wrapper video')
.append(preview)
.append(description);
return wrapper;
}
// Search media by type
function search(opts, media_type) {
var $container = $('#' + media_type + '-search-results');
var createComponentFunc = media_type === 'image' ? createImageComponent : createVideoComponent;
// Get Client ID and Client Secret for use in the Authorization header
var clientId = $('input[name=client_id]').val();
var clientSecret = $('input[name=client_secret]').val();
var jqxhr = $.ajax({
url: 'https://api.shutterstock.com/v2/' + media_type + 's/search',
data: opts,
headers: {
// Base 64 encode 'client_id:client_secret'
Authorization: 'Basic ' + window.btoa(clientId + ':' + clientSecret)
}
})
.done(function(data) {
if (data.total_count === 0) {
$container.append('<p>No Results</p>');
return;
}
$.each(data.data, function(i, item) {
var component = createComponentFunc(item);
$container.append(component);
});
})
.fail(function(xhr, status, err) {
alert('Failed to retrieve ' + media_type + ' search results:\n' + JSON.stringify(xhr.responseJSON, null, 2));
});
return jqxhr;
}
// On Page Load
$(function() {
$('#search-form').submit(function(e) {
e.preventDefault();
// Clear current media results
$('#image-search-results, #video-search-results').empty();
// Serialize form options
var opts = $("input[value != '']", this).serialize();
// Search and display images
search(opts, 'image');
// Search and display videos
search(opts, 'video');
return false;
});
});
This code is for searching images using shutterstock basic authentication.I want to create it using c#.
and i am using the following code :
LoadHttpPageWithBasicAuthentication(@"https://api.shutterstock.com/v2/images/232713811?view=full", "ClientID", "Clientsecrate");
private string LoadHttpPageWithBasicAuthentication(string url, string username, string password)
{
Uri myUri = new Uri(url);
WebRequest myWebRequest = HttpWebRequest.Create(myUri);
HttpWebRequest myHttpWebRequest = (HttpWebRequest)myWebRequest;
NetworkCredential myNetworkCredential = new NetworkCredential(username, password);
CredentialCache myCredentialCache = new CredentialCache();
myCredentialCache.Add(myUri, "Basic", myNetworkCredential);
myHttpWebRequest.PreAuthenticate = true;
myHttpWebRequest.Credentials = myCredentialCache;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
WebResponse myWebResponse = myWebRequest.GetResponse();
Stream responseStream = myWebResponse.GetResponseStream();
StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);
string pageContent = myStreamReader.ReadToEnd();
responseStream.Close();
myWebResponse.Close();
return pageContent;
}
But i am getting the error
The request was aborted: Could not create SSL/TLS secure channel.
Please help what is the error stuck with this problem.