1

下面的代码在本地工作得很好。但是,当我发布到我的主机并运行它时,它需要大约 20 秒,然后响应“无法连接到远程服务器”。

编辑:知道了,根据我的主机: '执行 HTTP 请求的 WebPermission,例如使用外部 XML Web 服务。(必须使用端口 1234 上的代理服务器 servername.tld 进行访问)"

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
4

1 回答 1

1

发现我的虚拟主机需要代理来处理任何 HTTP 请求。下面的更新功能完美运行!

<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 webProxy As New System.Net.WebProxy("<host proxy url", True)
        webClient.Proxy = webProxy
        Dim result As String = webClient.DownloadString(authURL)
        Return result
    Catch ex As Exception
        Return ex.Message
    End Try
End Function
于 2012-05-05T18:39:30.417 回答