WebRequest will not pass headers from ASP.NET MVC controller to Rest Wcf -


i have asp.net mvc 4 project when make http call using web request, headers not pass.

here code:

httpwebrequest client = (httpwebrequest)webrequest.create(url);         string svccredentials = convert.tobase64string(asciiencoding.ascii.getbytes("user1" + ":" + "test"));         client.headers.add("authorization", "basic " + svccredentials);         //just example code parse json response using javascriptserializer         using (webresponse svcresponse = (httpwebresponse)client.getresponse())         {             using (streamreader sr = new streamreader(svcresponse.getresponsestream()))             {                 javascriptserializer js = new javascriptserializer();                 string jsontxt = sr.readtoend();             }         } 

try this:

string enccred = convert.tobase64string(encoding.ascii.getbytes("user1" + ":" + "test")); string credential = string.format("{0} {1}", "basic", enccred); client.headers[httprequestheader.authorization] = credential; 

instead of:

client.headers.add("authorization", "basic " + svccredentials); 

hope helps.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -