调试应用程序 - 路径中的非法字符

时间:2016-07-19 22:10:12

标签: c#

我正在使用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;

        }
    }

0 个答案:

没有答案