小编Ash*_*ish的帖子

如何使用RestSharp发送请求

我试图使用RestSharp客户端POST请求,如下所示我将Auth Code传递给以下函数

public void ExchangeCodeForToken(string code)
{
    if (string.IsNullOrEmpty(code))
    {
        OnAuthenticationFailed();
    }
    else
    {           
        var request = new RestRequest(this.TokenEndPoint, Method.POST);
        request.AddParameter("code", code);
        request.AddParameter("client_id", this.ClientId);
        request.AddParameter("client_secret", this.Secret);
        request.AddParameter("redirect_uri", "urn:ietf:wg:oauth:2.0:oob");
        request.AddParameter("grant_type", "authorization_code");
        request.AddHeader("content-type", "application/x-www-form-urlencoded");

        client.ExecuteAsync<AuthResult>(request, GetAccessToken);
    }
}

void GetAccessToken(IRestResponse<AuthResult> response)
{
    if (response == null || response.StatusCode != HttpStatusCode.OK
                         || response.Data == null 
                         || string.IsNullOrEmpty(response.Data.access_token))
    {
        OnAuthenticationFailed();
    }
    else
    {
        Debug.Assert(response.Data != null);
        AuthResult = response.Data;
        OnAuthenticated();
    }
}
Run Code Online (Sandbox Code Playgroud)

但我得到了响应.StatusCode = Bad Request.任何人都可以帮助我如何使用Restsharp客户端发布请求.

c# windows-phone-7 restsharp

31
推荐指数
4
解决办法
9万
查看次数

如何在javascript中检测浏览器最小化和最大化状态

我试图找到浏览器最小化和最大化状态,因为我想相应的浏览器状态点击AJAX请求.

有谁知道如何使用JavaScript检测浏览器状态.

javascript

15
推荐指数
4
解决办法
3万
查看次数

GCDAsyncSocket startTLS 不起作用

我能够通过 IP 和端口连接到所需的套接字。

\n\n
- (void)socket:(GCDAsyncSocket *)sender didConnectToHost:(NSString *)host port:(UInt16)port {\n\n    [sender startTLS:nil];\n\n    if(self.createTCPSocketHelperDelegate && @selector(returnConnectedTCPSocket:forNASWithMacAddress:))\n    {\n        [self.createTCPSocketHelperDelegate returnConnectedTCPSocket:sender forNASWithMacAddress:_macAddress];\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我正在发送 TLS 设置字典 nil,因为它使用默认设置。\n它给了我如下错误

\n\n
Error Domain=kCFStreamErrorDomainSSL Code=-9806 "The operation couldn\xe2\x80\x99t be completed. (kCFStreamErrorDomainSSL error -9806.)" UserInfo=0x17d92420 {NSLocalizedRecoverySuggestion=Error code definition can be found in Apple\'s SecureTransport.h}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我不明白那里出了什么问题。请帮我提供一些连接到 SSL 服务器并使用 TCP/TLS 协议的示例代码。

\n\n

如有帮助,将不胜感激。先感谢您。:)

\n

iphone objective-c ios starttls gcdasyncsocket

2
推荐指数
1
解决办法
3277
查看次数