的NetworkCredential工作职位,但没有得到 [英] NetworkCredential working for POST but not GET

查看:245
本文介绍了的NetworkCredential工作职位,但没有得到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话使用Windows身份验证的WebAPI Web服务。我使用这个code在我的开发环境,因为我从一个盒子,是不是在域发展。

I'm calling a webAPI web service that uses windows authentication. I'm using this code in my development environment since I am developing from a box that is not on the domain.

 var req = (HttpWebRequest)WebRequest.Create(url);
 req.Credentials = new NetworkCredential("username", "password", "domain");
 req.Method = WebRequestMethods.Http.Post; //or get

当我做了后这一切正常,但是当我想要做一个得到它不起作用。

This works just fine when I do a post, but when I want to do a get it doesn't work.

当我访问了获取URL在Web浏览器中它要求我的用户名和密码,符合市场预期。我输入正确的用户名和密码,GET工作。

When i visit the url for the get in a web browser it asks for my username and password, as expected. I enter the username and password correctly and the GET works.

推荐答案

尝试基本身份验证如下:

Try basic authentication as below:

string credentials = String.Format("{0}:{1}", username, password);
byte[] bytes = Encoding.ASCII.GetBytes(credentials);
string base64 = Convert.ToBase64String(bytes);
string authorization = String.Concat("Basic ", base64);
req.Headers.Add("Authorization", authorization);

这篇关于的NetworkCredential工作职位,但没有得到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆