How to call web API URL in C# windows application and get response -


i facing issue while calling api url in windows application . code follow.

        var client1 = new restclient("http://stagingapi.bulkmro.com/index.php/product/736387");         var request1 = new restrequest(method.get);         request1.addheader("postman-token", "79dbc057-2279-0d13-9d98-484efbdce8da");         request1.addheader("cache-control", "no-cache");          //request1.addheader("authorization", "api rjnozmvxrflusky1vmxsovboahvrm1lptmzweffyrui4zvbwuwhmta==");         request1.addheader("authorization", "api '" + key + "'");         irestresponse response1 = client1.execute(request1);         string str222 = response1.tostring();         string aa1 = response1.content.tostring();         var jss1 = new javascriptserializer();         var dict1 = jss1.deserialize<dictionary<string, string>>(aa1);         string key1 = dict1["value_id"]; 

but giving response unauthorised. please suggest answer.

it looks api using basic access authentication. baa header key authorization , value basic {base64 hash}. in example looks setting value api {base64 hash}. sure api expecting "api" in value , not "basic"?

also, in code:

request1.addheader("authorization", "api '" + key + "'");

you sending single quotes around hash. should not case. sending api '{base64 hash}'. need remove 'single quotes'. this:

request1.addheader("authorization", "api " + key);

if doesn't work, try this:

request1.addheader("authorization", "basic " + key);


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -