我试图调用REST Api来获取一些JSON数据,但我无法连接它。我认为它需要缓存的cookie或其他东西才能工作。任何使用过REST Bitbucket.org api的想法或人物?这是api地址我正在使用https://api.bitbucket.org/1.0/user/repositories/。如果您直接在网络浏览器中使用它,它就可以工作。
HttpWebRequest request = WebRequest.Create(
ConfigurationManager.AppSettings["RESTApiPath"]) as HttpWebRequest;
request.Credentials = new NetworkCredential(
ConfigurationManager.AppSettings["user"],
ConfigurationManager.AppSettings["pass"]);
//request.PreAuthenticate = true;
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Console application output
string jsonData = reader.ReadToEnd();
if (!string.IsNullOrWhiteSpace(jsonData))
ParseNames(jsonData);
}