原本使用的網頁jquery如下,可以把msg=$("#content").val() 給POST到遠端API
$("button").click(function(){
$.post("API網址",{msg:$("#content").val(),},
function(e){
console.log(e);
});
});
想要改寫成C#之後多些彈性
但POST出去的內容,API一直回應說抓不到msg的值
string param = "msg=我要傳的訊息";
byte[] bs = Encoding.UTF8.GetBytes(param);
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("API網址");
req.Method = "POST";
req.ContentType = "application/json";
req.ContentLength = bs.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(bs, 0, bs.Length);
}
不曉得哪邊出了問題,搞了兩天還搞不定
原本想說折衷一下乾脆改用shellwindows去控制網頁傳值
但好死不死這網頁只能在chrome和edge運作,換成IE就一樣post不到
偏偏VS又只支援IE的control,快瘋了...-.-