我無法確定您是否可以構建.Net 2.0 REST客戶端。我搜索了高和低,但只有遇到提及使用3.5和WCF的結果。如果可能的話,我希望能夠使用2.0構建一個.Net REST客戶端。我對我想要完成的任務有一個大致的瞭解,並且遇到了針對經過身份驗證的REST Web服務傳遞參數的問題。我正在尋找.Net 2.0 vb或c#的示例。.NET 2.0 Rest客戶端
目前我正在嘗試使用HttpWebRequest的,但遇到了問題:
我上的GetResponse()行接收 Dim ord As order
Dim url As String = String.Format("https://login.someurl.com/rest/order/{0}", Web.HttpUtility.UrlEncode(id))
Dim request As HttpWebRequest = WebRequest.Create(New Uri(url))
request.Method = "GET"
request.ContentType = "application/json"
request.Credentials = New NetworkCredential(UserName, Password)
Dim resp As HttpWebResponse = Nothing
resp = request.GetResponse()
Dim reader As StreamReader = New StreamReader(resp.GetResponseStream)
Dim response As String = reader.ReadToEnd
ord = JsonConvert.DeserializeObject(response)
錯誤消息爲:「遠程服務器返回錯誤:(412)參數錯誤。 「
您確定該服務支持json嗎? – dkackman
@dkackman正面,這是在api文檔 –