インタフェースアクセス方式(メモ)


                List<Object> ParamList = new List<Object>();

                ParamList.Add(new

                {

                    res_id = context.Request.Form["ResId"]

                });

                string jsonData = new JavaScriptSerializer().Serialize(ParamList);

                string responseData = String.Empty;

                byte[] bs = Encoding.ASCII.GetBytes(jsonData);

                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://xxx.com/");

                req.ContentType = "application/json";

                req.MediaType = "application/json";

                req.Accept = "application/json";

                req.Method = "POST";

                req.ContentLength = bs.Length;

                using (Stream reqStream = req.GetRequestStream())

                {

                    reqStream.Write(bs, 0, bs.Length);

                }

                using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream()))

                {

                    string i = reader.ReadToEnd();

                    Dictionary<string, IList<Object>> PicJson = new JavaScriptSerializer().Deserialize<Dictionary<string, IList<Object>>>(i);

                    foreach (var item in PicJson[context.Request.Form["ResId"]])

                    {

                        string PicUrl = context.Request.Form["PicUrl"];

                        string SourceUrl = (item as Dictionary<string, object>)["pic_url"].ToString();

                    }

                }

Post
HttpWebRequest _WebRequest = (HttpWebRequest)WebRequest.Create(Request.QueryString["url"]);

_WebRequest.Method = "GET";

WebResponse _WebResponse = _WebRequest.GetResponse();

StreamReader _ResponseStream = new StreamReader(_WebResponse.GetResponseStream());

ViewBag._StrResponse = _ResponseStream.ReadToEnd();

_WebResponse.Close();

_ResponseStream.Close();

return View();

Get