Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

trying to post to a rest url and get a response in C#.NET

$
0
0

ok here is my code , I get no errors so I am hoping that I am actually receiving a response back , it should be json like this below what I am wondering is how do I now parse it out IE get thecontentId

{"userId": 189,"contentId": 1073,"firstName": "Test","lastName": "Person","preferredName": "Updated preferred name","salutation": "Mr","email": "test.person@test.com","username": "ryan","jobTitle": "Chief Tester","timeZone": "Pacific Standard Time","defaultCulture": "fr","birthday": "Jan 23","phoneNumbers": {"fax": "777-777-7777","mobile": "888-888-8888","tel": "666-666-6666"
    },"images": {"small": "/profileimage/193821700000/1357/50x50/False/0,0,200,200/test.png","medium": "/profileimage/193821700000/1357/250x250/False/0,0,200,200/test.png","large": "/profileimage/193821700000/1357/0x0/False/0,0,200,200/test.png"
    }
}

here is the inline code in an ASPX


<%@ import namespace="System" %>
<%@ import namespace="System" %>
<%@ import namespace="System.Collections.Generic" %>
<%@ import namespace="System.IO" %>
<%@ import namespace="System.Net" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import namespace="Newtonsoft.Json" %>
<%@ Import namespace="Newtonsoft.Json.Linq" %>


<%@ Page Language="C#" Debug="true" %>

<html>
<body>

<%

var PageRequest1 = WebRequest.Create("https://fin.website.com/api/user/username") as HttpWebRequest;
var authToken = Request.Cookies["tfcookie"].Value;
var postData = "username=" + Request.QueryString["samaccountname"];
    postData += "&token=" + authToken;
var data = Encoding.ASCII.GetBytes(postData);
PageRequest1.Method = "POST";

PageRequest1.ContentType = "application/x-www-form-urlencoded";
PageRequest1.ContentLength = data.Length;
using (var stream = PageRequest1.GetRequestStream())
{
    stream.Write(data, 0, data.Length);
}

var response = (HttpWebResponse)PageRequest1.GetResponse();


var reader = new StreamReader(response.GetResponseStream()).ReadToEnd();

%>


</body>
</html>


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>