I'm making HttpWebResponse
to an API, the return data is in JSON
format.
I receive no errors when compiling, but when I run the application I receive the following error message:
illegal characters in path
I think the problem is something to do with the //Get Response
private void RequestVehicleData()
{
string make = "";
string postcode = "";
string registration = (string)(Session["regNo"]);
make = txtmake.Text;
postcode = txtpostcode.Text;
//Make Request
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(String.Format("https://www.check-mot.service.gov.uk/api/v1/mot-history/{0}/{1}/", registration, make));
httpWebRequest.Method = "GET";
httpWebRequest.ContentType = "application/json";
httpWebRequest.Accept = "application/json";
//Get Response
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
String vehicle = File.ReadAllText(result);
Vehicle v1 = JsonConvert.DeserializeObject<Vehicle>(vehicle);
lblColor.Text = v1.vehiclecolour;
lblModel.Text = v1.vehiclemodel;
lblReg.Text = v1.Registration;
}
}