asp.net - C# Error 401 - Invalid username or password -


i'm trying make requests api. when made request using postman, works. in c#, doesn't, returns error 401. checked , login , password right. can me?


code:

public jsonresult test() {     var document = new htmlagilitypack.htmldocument();      var password = calculatemd5hash("******");      var httprequest =(httpwebrequest)webrequest.create(string.format("https://api.akna.com.br/emkt/int/integracao.php?user={0}&pass={1}&xml={2}",     "mail@mail.com",      password,     @"<main>     <emkt trans='19.10'>     <datainicial>2016-07-01 10:00:00</datainicial>     <datafinal>2016-07-02 10:00:00</datafinal>     </emkt>     </main>"));      httprequest.method = "post";     httprequest.contenttype = "application/x-www-form-urlencoded";      try     {     var httpwebresponse = (httpwebresponse)httprequest.getresponse();      var responsestream = httpwebresponse.getresponsestream();      if (responsestream != null)     {      var sr = new streamreader(responsestream, encoding.default);      document.loadhtml(sr.readtoend());    }     return json(new { statuscode = 200 }, jsonrequestbehavior.allowget);    }   catch (exception ex)   {   return json(new { statuscode = 500, erro = ex.message }, jsonrequestbehavior.allowget);  }  } 

the problem encoding of parameters. solved problem: http://rest.elkstein.org/2008/02/using-rest-in-c-sharp.html


Comments