首页 新闻 搜索 专区 学院

Asp.Net WebApi

0
悬赏园豆:10 [已关闭问题] 关闭于 2015-09-25 16:46

请求的资源不支持 http 方法“GET”。

请求就报这个错,路由没有修改过。然后请求别的Api,就是找不到资源。。 控制器名称这些名字不会错的

问题补充:

iisexpress.exe Information: 0 : Response, Status=405 (MethodNotAllowed), Method=GET, Url=http://localhost:45457/api/user/, Message=“内容类型=“application/xml; charset=utf-8”,内容长度=未知”

学习态度要端正的主页 学习态度要端正 | 初学一级 | 园豆:55
提问于:2015-09-25 16:25
< >
分享
所有回答(3)
0

你这个让别人怎么看

MrNice | 园豆:3107 (老鸟四级) | 2015-09-25 16:26
0

楼主。你的后台代码要开光吗?免费哦

Giant150 | 园豆:963 (小虾三级) | 2015-09-25 16:44
0

不支持GET 肯定是POST 了啊,你看看API文档怎么解释的啊

我印象中,微博的API基本都是POSt

/// <summary>
        /// 获得用户信息
        /// </summary>
        /// <param name="access_token">授权编号</param>
        /// <param name="uid">用户微博帐号</param>
        /// <returns></returns>
        public SinaUser GetSinaUserInfo(string access_token, string uid)
        {
            Stream outstream = null;
            Stream instream = null;
            StreamReader sr = null;
            HttpWebResponse response = null;
            HttpWebRequest request = null;
            Encoding encoding = Encoding.UTF8;
            try
            {

                request = (HttpWebRequest)WebRequest.Create("https://api.weibo.com/2/users/show.json?source ="+AppKey+"&access_token=" + access_token + "&uid=" + uid + "");
                CookieContainer cookieContainer = new CookieContainer();
                request.CookieContainer = cookieContainer;
                request.AllowAutoRedirect = true;
                request.Method = "GET";
                request.ContentType = "application/x-www-form-urlencoded";

                response = request.GetResponse() as HttpWebResponse;
                request.GetResponse();
                instream = response.GetResponseStream();
                sr = new StreamReader(instream, encoding);


                JsonTextParser parser = new JsonTextParser();

                JsonObjectCollection obj = parser.Parse(sr.ReadToEnd().Replace("[]", "null")) as JsonObjectCollection;
                JsonUtility.GenerateIndentedJsonText = false;

                SinaUser model = new SinaUser();
                model.Bi_followers_count = int.Parse(obj["bi_followers_count"].GetValue().ToString());
                model.Blog = obj["url"].GetValue().ToString();
                model.Description = obj["description"].GetValue().ToString();
                model.Domain = obj["domain"].GetValue().ToString();
                model.Favourites_count = int.Parse(obj["favourites_count"].GetValue().ToString());
                model.Followers_count = int.Parse(obj["followers_count"].GetValue().ToString());
                model.Friends_count = int.Parse(obj["friends_count"].GetValue().ToString());
                string gender = obj["gender"].GetValue().ToString();
                model.Gender = gender == "m" ? "" : "";
                model.ImageUrl = obj["avatar_large"].GetValue().ToString();
                model.Name = obj["screen_name"].GetValue().ToString();
                model.Place = obj["location"].GetValue().ToString();
                model.Profile_url = obj["profile_url"].GetValue().ToString();
                model.Statuses_count = int.Parse(obj["statuses_count"].GetValue().ToString());
                model.Uid = obj["id"].GetValue().ToString();
                model.Verified = bool.Parse(obj["verified"].GetValue().ToString());
                model.Verified_reason = obj["verified_reason"].GetValue().ToString();
                model.AccessToken = access_token;
                if (model != null)
                {
                    return model;
                }
                return null;


            }
            catch(Exception ex)
            {
                return null;
            }
        }
View Code

 

imluzhi | 园豆:37 (初学一级) | 2015-09-25 16:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册