我正在使用HttpWebResponse
API,返回数据为JSON
格式。
编译时没有收到任何错误,但是当我运行应用程序时,收到以下错误消息:
路径中的非法字符
我认为问题与 // 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;
}
}