3
我需要在URL中包含curl -H'Context-type:application/json'不確定如何做到這一點,服務器響應到目前爲止404,任何幫助非常讚賞,如何使GET RESTful請求
private string RequestVehicleData()
{
string make = "";
string postcode = "";
string registration = (string)(Session["regNo"]);
make = txtmake.Text;
postcode = txtpostcode.Text;
//Make Request
var httpWebRequest = (HttpWebRequest)WebRequest.Create(string.Format("https://www.check-mot.service.gov.uk/api/v1/mot-history/{0}/{1}/", registration, make));
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "GET";
//Get Response
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
return result;
}
}
的可能的複製[?如何設置在C#中的HttpWebRequest的內容(http://stackoverflow.com/questions/5527316/how-to-set -the-內容的-AN-HttpWebRequest的式-c)的 –