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.

1
  • 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 Commented May 7, 2015 at 11:57

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.