The access token passed on the WebClinet on C# is disabled.

Asked 2 years ago, Updated 2 years ago, 144 views

Attempting EPO open patent service on VS2019, .net framework 4.7.2.
I was able to get the access token while looking at the specification.

request.Headers.Authorization=newSystem.Net.Http.Headers.AuthenticationHeaderValue(
    "Basic", Convert.ToBase64 String (Encoding.ASCII.GetBytes(client_id+":"+client_secret)));
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
var parameters = new Dictionary <string, string>() {
    { "grant_type", "client_credentials"},
};
request.Content = new FormUrlEncodedContent (parameters);
var response = httpClient.SendAsync(request);
response.Wait();
string result=response.Result.Content.ReadAsStringAsync().Result;

Next, in order to access the resource by referring to page 50 of the specification, I have passed the token from the results I just obtained.
As a result, the error code 400 invalid_access_token is returned.
I don't really understand the specifications, so I'm making it.Is the designation method bad?
Request Body: EP1000000.A1 in the specification can be set in the Content of HttpRequestMessage?

HttpClient httpClient=new HttpClient();
HttpRequestMessage request = new HttpRequestMessage();
request.Method = HttpMethod.Post;
request.RequestUri = newUri("http://ops.epo.org/rest-services/published-data/publication/epodoc/biblio");
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer"+token);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/exchange+xml"));
request.Content = new StringContent("EP1000000.A1");
varres = httpClient.SendAsync(request);
res.Wait();
string result=res.Result.Content.ReadAsStringAsync().Result;

c# oauth rest

2022-09-30 15:45

1 Answers

Thank you for your comment.
When passing token, the header setting was changed to the following and moved.

request.Headers.Authorization=new System.Net.Http.Headers.AuthenticationHeaderValue("Authorization", "Bearer" + token);

I'm sorry.Sorry for the inconvenience caused by not knowing the basics.


2022-09-30 15:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.