但因為本人想說跟風一下改成Web Api 來玩玩看好了,
所以就建立一個Wep Api 專案MyWebAPI 提供我呼叫
如上圖所示我建立了一個WebForm1.aspx的網頁
為了方便,接下來在Page_Load的部份呼叫我們建立的Web api
將來大家可以寫一個function來呼叫

1.宣告HttpClient
2.設定web api 的Uri
3.用HttpResponseMessage 來接收Class control回傳的值
4.宣告一個IEnumerable<ClassModel> 來存抓回來的資料
ClassModel 是MyWebAPI 裡的一個Class
接下來實際執行看看
哇! 居然GG了!
第一時間我還真不知道這是錯在哪裡@#$%^&
這時當然要找Google大神出來幫忙了
參考 https://stackoverflow.com/questions/36090334/httpcontentextensions-readasasync-error
解法:
在Webconfig裡
加上
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
再次執行看看
搞定囉!
沒有留言:
張貼留言