Click here to Skip to main content
15,891,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have rest api url like this
https://example.com/ProductAPI/api/V1/getproduct.
This api has api_key,username and password.How can I access this api and getproduct details using c#.
The token which will get from another url
https://example.com/ProductAPI/ by passing username,password,client_key and generictype

What I have tried:

WebRequest request = WebRequest.Create(@"https://example.com/ProductAPI/api/V1/getproduct");

request.Method = "GET";
request.Headers.Add("api_key","5g13441f-6915-4a34-8a53-bcb4er88b554");
request.Headers["Authorization"] = "Basic" + Convert.ToBase64String(Encoding.Default.GetBytes("admin:123"));
request.ContentLength = 0;
request.ContentType = @"application/json; charset=utf-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string jsonResponse = string.Empty;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
jsonResponse = sr.ReadToEnd();
Console.WriteLine(jsonResponse);
Console.ReadLine();
}
Posted
Updated 18-Jul-16 4:39am
v2
Comments
ZurdoDev 18-Jul-16 11:54am    
You have to ask the provider of the API. Some will accept a token in the query string and others may require it to be posted. You just need to ask.

1 solution

Refer following link
link1
link2

I hope it will work for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900