1

I am working on a university project in which I need to get some product information out of the database of outpan.com into a string or an array of strings.

I am new to coding, that's why I am needing quite a lot of help still. Does anyone of you know how to send a request & get the answer from a c#-environment (Windows Form Application)?

The description on outpan itself (https://www.outpan.com/developers.php) says to send the call by using HTTPS in curl, but what does it practically mean? Do I need to install extra libraries?

I would be glad, if someone could help me with this problem or provide me with a tutorial on how to make these curl calls to a database starting from a c# environment.

If there are more information needed about my settings, let me know.

kaemizzo
  • 21
  • 4
  • This is really too broad a question. Forget about *curl*, from .Net you would use the built-in `HttpWebRequest`/`WebRequest `. What you are calling is called a REST API there are many examples, E.g.: [Calling a rest api with username and password - how to](http://stackoverflow.com/questions/18347055/calling-a-rest-api-with-username-and-password-how-to) – Alex K. May 07 '15 at 11:57

1 Answers1

1

The Outpan API uses Basic HTTP auth, so all the request will need to have a header like:

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

In the request. In order to do that with C#, you could do the following:

var request = (HttpWebRequest)WebRequest.Create("https://api.outpan.com/v1/products/0796435419035");
var encodedString = Convert.ToBase64String(Encoding.Default.GetBytes("-your-api-key-here-:"));
request.Headers["Authorization"] = "Basic " + encodedString;
var response = request.GetResponse();

For a full description of the header, check out the wiki page http://en.wikipedia.org/wiki/Basic_access_authentication. Note that the base64 encoded string can be in the form [username]:[password], but the outpan api docs ( https://www.outpan.com/developers.php ) write that they do not use the password part.

Also see: Forcing Basic Authentication in WebRequest for a nice method wrapper for this logic.

Community
  • 1
  • 1
Jochen van Wylick
  • 5,303
  • 4
  • 42
  • 64
  • 1
    I'd like to thank all of you for your answers. They are way more than I expected. @spike Especially this one helped me to make the code run. Since I needed the output in a "string"-format, I added this to the code: String responseString; using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); responseString = reader.ReadToEnd(); } MessageBox.Show(responseString); – kaemizzo May 14 '15 at 10:38