webapi建立及POST GET訪問

2022-04-06 01:07:59 字數 1807 閱讀 4062

我使用的是vs2015,點開新建專案,安裝如下操作執行:

在controllers 資料夾下建立乙個示例控制器: apicontroller

至此webapi建立完成。

[httpget]:表示使用get訪問;(同時get方式訪問可以給函式命名為get***)

[httppost]:表示使用post訪問;

[acceptverbs("get", "post")]:post和get方法都支援;

getresponsestream()方法獲取http響應的資料流,並嘗試取得url中所指定的網頁內容

//streamreader類的read方法依次讀取網頁源程式**每一行的內容,直至行尾(讀取的編碼格式:utf8)

rstr =sr.readtoend();

sr.close();

webresponse.close();

////

避免頁面出現,只返回json欄位

//return result;

return

rstr;

}view code

訪問**:http://localhost:58601/api/api/getsendrequest?mo=001000012111

(http://localhost:58601/api/控制器名/方法名)

}訪問**:http://localhost:58601/api/api/sendrequest?param=0&moid=1&partno=2&stationid=t

(http://localhost:58601/api/控制器名/方法名)

WebApi 空專案建立WebApi工程步驟

1 新建空的asp.net應用程式 3 在工程下面建controller和models資料夾 4 在models資料夾下面新建類 storage using system using system.collections.generic using system.linq using system....

建立 web API程式及在IIS上部署

1.在 visual studio 中建立乙個新的 asp.net core web 應用程式 2.選擇api 3.建立models資料夾並新建類user public class user public string m userpassword public string m userprevi...

建立並管理 WebApi

右鍵專案選擇屬性,找到web選項,啟動操作選擇當前頁面,即可找回頁面,這個問題造成的原因為手動設定起始頁。url defaults new第一步更改路由 這段 是通過引數方式設定url的路徑。相對應的controller是資料夾名稱,index是頁面的檔名。如果想自行設定主頁面為htmlwebapi...