The code below works great locally. However, when I publish to my host and run it it takes ~20 seconds and then responds with “Unable to connect to the remote server”.
edit: Got it, according to my host: ‘ WebPermission to perform HTTP requests, e.g. to use external XML Web Services. (The access must be done using a proxy server servername.tld on port 1234)”
Javascript:
function getAuthCode() {
$.ajax({
type: "POST",
cache: false,
url: "backend.asmx/getAuthCode",
contentType: "application/json",
dataType: "json",
success: function (data) {
//do whatever
},
error: function (request, status, error) {
alert('getAuthCode ERROR: ' + error);
}
});
};
ASMX:
<WebMethod()> _
Public Function getAuthCode() As String
Dim appID As String = "<my appid>"
Dim secretCode As String = "<my apps secret code>"
Dim authURL As String = "https://graph.facebook.com/oauth/access_token?client_id=" + appID + "&client_secret=" + secretCode + "&grant_type=client_credentials"
Try
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString(authURL)
Return result
Catch ex As Exception
Return ex.Message
End Try
End Function
Discovered my webhost requires a proxy for any HTTP requests. Updated function below works perfectly!