问题描述
我对OAuth有点陌生,但学习。我有的是这个教程我想跟着。我想遵循简单的3行示例生物 - 检索传记记录数据:
I'm a little bit new to OAuth, but learning. What I have is this tutorial I'm trying to follow. I'm trying to follow the simple 3-line example under "Bio - retrieving biographical record data": https://members.orcid.org/api/tutorial-retrieve-data-public-api-curl-12-and-earlier
我需要做的是使用C#控制台程序来做这个而不是CURL,我想使用HttpClient命名空间。我有我自己的客户端ID和客户端密码使用。我试图使用这个公共API获取一个访问令牌存储在哪里,然后调用获取XML数据像这个例子。我的问题是,我不知道如何将他们的CURL调用C#代码。我不是使用ASP.NET网站为此...这一切都需要在一个C#控制台程序。
What I need to do though, is use a C# console program to do this instead of CURL, I imagine using the HttpClient namespace. I have my own client id and client secret to use. I'm trying to use this public API to get an access token to store wherever, then make calls to get XML data like this example does. My problem is that I don't know how to convert their CURL calls to C# code. I'm NOT using an ASP.NET website for this...this all needs to be done in a C# console program.
推荐答案
如果您计划对许多不同的任务使用curl,而不是重写工具。
If you are planning on using curl for many different tasks, instead of rewriting the tool. Just download the windows compatible version and embed it as a resource in your console application.
curl.exe的Windows(32位)版本 -
Windows (32 bit) version of curl.exe - https://akamai.bintray.com/5a/5aa976c1cfc96d95a12cb469ce9bbb1b193ae7599d446f4a22d023a585c5ffe9?gda=exp=1455730084~hmac=85d7d80271ecba52893dacb956690dedd020c0ad61f2943b28adcc43ce14e45a&response-content-disposition=attachment%3Bfilename%3D%22curl-7.47.1-win32-mingw.7z%22&response-content-type=application%2Fx-www-form-urlencoded
编辑 - 类似这样:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "C:\CURL\curl.exe";
p.StartInfo.Arguments = "-i -L -H 'Accept: application/json' -d 'client_id=APP-GWTDOE3CX89FH7FD' -d 'client_secret=5160c539-4ec9-4e8c-8966-580df68b494f' -d 'scope=/read-public' -d 'grant_type=client_credentials' 'https://pub.sandbox.orcid.org/oauth/token'";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine(output);
这篇关于如何调用REST Web API的访问令牌与这些cURL命令 - 在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!