相关疑难解决方法(0)

向标头添加授权

我有以下代码:

...
AuthenticationHeaderValue authHeaders = new AuthenticationHeaderValue("OAuth2", Contract.AccessToken);
string result = await PostRequest.AuthenticatedGetData(fullUrl, null, authHeaders);
return result; 
...

public static async Task<string> AuthenticatedGetData(string url, FormUrlEncodedContent data, AuthenticationHeaderValue authValue)
{

    HttpClient client = new HttpClient();
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authValue.Parameter);

    HttpResponseMessage response = await client.PostAsync(new Uri(url), data);

    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
    response.EnsureSuccessStatusCode();
    string responseBody = await response.Content.ReadAsStringAsync();
    return responseBody;
}
Run Code Online (Sandbox Code Playgroud)

响应=等待部分只是继续循环,没有任何反应.我有什么想法我做错了吗?

问题是,我如何发送以下标题:

Authorization: OAuth2 ACCESS_TOKEN
Run Code Online (Sandbox Code Playgroud)

到外部网络api

c# async-await dotnet-httpclient windows-phone-8

22
推荐指数
3
解决办法
7万
查看次数